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;
};
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;
};