Categorized | Javascript

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

<script language=”javascript”>
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;
}
}
</script>

How can use this script?

<input type=”text” name=”txt” id=”emailID” />
<input type=”button” name=”submit” onclick=”return checkEmail()” value=”Test”/>

1 Comments For This Post

  1. Niraj Says:

    Very useful script
    Thanks….

Leave a Reply


  • Popular
  • Latest
  • Comments
  • Tags
  • Subscribe

44,034
Unique
Visitors
Powered By Google Analytics