• Sun, Nov 2011
  • RSS
  • Newsletter
  • Become a Fan!
  • Follow On Twitter
    • Subcribe to Our RSS Feed

    Check Email Address with JavaScript and Regular Expressions

    Posted In Javascript - By admin On Tuesday, July 28th, 2009 With 1 Comment

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

    How can use this script?

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

    About -

    Displaying 1 Comments
    Have Your Say

    1. Niraj says:

      Very useful script
      Thanks….

      [Reply]

    Leave a comment

    XHTML: You can use these tags: