I have the following code as part of my email validation script. I’d like to learn more about the variable reg but don’t know how to find relevant information because I do not know what the syntax is called. Could someone direct me to the proper resource or tell me the name of this type of syntax?
function validate(form_id,email) {
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var address = document.forms[form_id].elements[email].value;
if(reg.test(address) == false) {
alert('Invalid Email Address');
return false;
}
}
It’s called a regular expression.
There are a lot of resources on regexes, and particularly about regexes in JS. Here is a guide that explains how to use them:
http://www.javascriptkit.com/javatutors/re.shtml
and a guide to the patterns themselves:
http://www.javascriptkit.com/javatutors/redev2.shtml