Wednesday, May 5, 2010

Regular Expression (Regex)

This link has good material about Regular Expression (Regex) in Javascripts.



The test() function of the RegExp object is a shortcut to exec() != null. It takes the subject string as a paarameter and returns true or false depending on whether the regex matches part of the string or not.

You can call these methods on literal regular expressions too. /\d/.test(subject) is a quick way to test whether there are any digits in the subject string.

Example:

var patternAbcLoan= /^Abc Loan/;

if(patternAbcLoan.test("Abc Loan is right")) {

alert('Passed');

}