Click to See Complete Forum and Search --> : Deciphering email validation variable


mallkuma
12-30-2005, 12:24 PM
Hi,

I am trying to understand a JavaScript code that validates e-mail IDs. These variables are downright scary to me. I cannot make any sense out of it. Someone please help me in deciphering this variable. What does this actually mean? Or please point me to appropriate web page where I can further study on this.

var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/
var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/


Thanks!!!

Kumar

function validateEmail (vfld, // element to be validated
ifld, // id of element to receive info/error msg
reqd) // true if required
{
var tfld = trim(vfld.value); // value of field with whitespace trimmed off
var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/
if (!email.test(tfld)) {
msg (ifld, "error", "ERROR: not a valid e-mail address");
setfocus(vfld);
return false;
}

var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/
if (!email2.test(tfld))
msg (ifld, "warn", "Unusual e-mail address - check if correct");
else
msg (ifld, "warn", "");
return true;
};

phpnovice
04-20-2006, 10:51 AM
It's called a Regular Expression. It's syntax and meaning can be found here:

http://msdn.microsoft.com/library/en-us/script56/html/ab0766e1-7037-45ed-aa23-706f58358c0e.asp

felgall
04-20-2006, 04:45 PM
I have a series of tutorials on regular expressions at http://javascript.about.com/od/regularexpressions/