Thursday, 23 June 2011

Validate email id in JavaScript


function validateEmail(elementValue)
{ 
    var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; 
    return emailPattern.test(elementValue);
}

//Called in a JavaScript Validate Method
If(!validateEmail(“abc@gmail.com”))
{   
      alert(“Invalid email id.”);     
}       

No comments:

Post a Comment