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



Reader's Comments

  1. Jigar Mehta | June 26th, 2009 at 7:07 pm

    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. Alpesh Mansata | June 29th, 2009 at 10:49 am

    Thanks Jigar, fixed it.

Leave a Comment