Check Email Address with JavaScript and Regular Expressions
In forms when using email ID fields it is a good idea to use client side validation along with your programming language validation.The following script shows how you can validate an email address for a form
function checkEmail()
{
var email = document.getElementById(‘emailID‘);
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value))
{
alert(‘Invalid email address‘);
return false;
}
}
var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!filter.test(email.value))
{
alert(‘Invalid email address‘);
return false;
}
}
How can use this script?
type=”text” name=”txt” id=”emailID” />
type=”button” name=”submit” onclick=”return checkEmail()” value=”Test”/>
type=”button” name=”submit” onclick=”return checkEmail()” value=”Test”/>
Very useful script
Thanks….
[Reply]