Friday, May 14, 2010

Java Script function - Email Validation

Java Script function - Email Validation
function emailValidator(elem, helperMsg)
{
var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,20}$/;
if (elem.value != "")
{
if(elem.value.match(emailExp))
{
return true;
}
else
{
alert(helperMsg);
elem.focus();
elem.select();
return false;
}
}
}

Use of this function: you can call on onblur event of text box
onblur="emailValidator(this,'Invalid official mail id-1.')"


No comments:

Post a Comment