Regular Expression Validation using Exec() in Javascript
Exec() method of the Javascript is the Regular Expression object (RegExp::exec()). exec() method allows to use the regular expression object and finds the pattern defined. RegExp.$1,$2 .. $9 are the first through ninth parenthesized expressions matched.
The following code snippet shows how exex() method works.
//Paste the code into script tag
function getInfo()
{
reg = /(\w+)\s(\d+)/;
var str="Shanthi 22";
reg.exec(str);
document.write("Name: " +RegExp.$1+"
Age :"+RegExp.$2);
}
//Paste the code into body tag
onload()="getInfo()"
The following code snippet shows how exex() method works.
//Paste the code into script tag
function getInfo()
{
reg = /(\w+)\s(\d+)/;
var str="Shanthi 22";
reg.exec(str);
document.write("Name: " +RegExp.$1+"
Age :"+RegExp.$2);
}
//Paste the code into body tag
onload()="getInfo()"
Labels: Regular Expression

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home