javascript validate email

    function validateEmail(email) {
           var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9\-\.])+\.([A-Za-z]{2,4})$/;
           if(reg.test(email) == false) {
                return false;
           }
           return true;
    }

Random Posts

About Alpesh Mansata

I am a 25-year-old guy living at a beautiful green city Pune . I have a post graduate degree in Information Technology from K.S.School of Business Management and Research. A Zend certified PHP5 Engineer with over 4 years of experience working with PHP, AJAX, MySql and the Mambo/Joomla CMS. In my full-time job, I am a Senior Software Engineer working at Xoriant. Most recently, I have been working on SchoolFinder module on www.education.com In my spare time (if there is such a thing), I volunteer with the Rotaract club of Ahmedabad Airport.
This entry was posted in Alpesh Mansata. Bookmark the permalink.

2 Responses to javascript validate email

  1. Jigar Mehta says:

    Very cool!
    I think there is one bug in the code.. The regex considers “_” in the URL portion as valid email address, though as per URL RFC1738 (http://www.faqs.org/rfcs/rfc1738.html – pls see Section 2.1) valid characters for a URL does not include “_” (underscore).. And I think, I have never seen any URL with underscore in it.. so, email id with an underscore in domain part will always be invalid.
     
    This occured to me just because I’d reported this in one of my products :)
     

  2. Thanks Jigar, fixed it.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>