regex - In the angular, how can we check if a value match a pattern? -


how can check if value match pattern in code?

not use ng-pattern in function.

thanks.

use pure javascript match function.

var str = "the rain in spain stays in plain";  var res = str.match(/ain/g); 

res array matched values. can test if there match checking array length:

if ( res.length > 0 )      console.log("match"); 

from here

use in directive, better controller since in angular 2 there no controllers.


Comments

Popular posts from this blog

amazon web services - S3 and apache mod_proxy with basic authentication -

How to install ruby on rails -

powershell - This solution contains one or more assemblies targeted for the global assembly cache -