1. Bret
    February 11, 2008 @ 1:10 pm

    Hey, nice useful piece of code. Always nice to find something that takes a fairly common task, such as email validation, and breaks down the logic and provides a simple piece of code in the end.


  2. Mastan Jhoni
    February 14, 2008 @ 5:50 am

    hey, nice explanation, its helped me allott.


  3. More JavaScript Regular Expressions
    February 20, 2008 @ 3:14 pm

    […] I wrote the JS regular expression article last week I had no idea that it will attract so many visitors. Not only did so many people read […]


  4. Validate Zip code using JavaScript Regular expression
    February 20, 2008 @ 10:04 pm

    […] to validate zip code using regular expression in JavaScript. Previously we talked about validating email and Social Security number using JS […]


  5. Validate U.S Phone Numbers using JavaScript Regular expression.
    February 28, 2008 @ 10:44 pm

    […] JavaScript regular expression to validate U.S phone number. Previously we talked about validating email , Social Security number and zip code using JS […]


  6. Latha p
    April 17, 2008 @ 12:52 am

    Hi , email validation code present in this site is very nice and it is very useful to validate email address using regular expressions. My sincere thanks to the programmer who posted this. This help me alot.

    Thanks & Regards,


  7. Latha
    April 21, 2008 @ 4:20 am

    Hi can anyone help me how to invalidate the session , when i am clicking LOGOUT button. I use session.invalidate() method , the page has been expired. But when click back button on browser it goes to back page. How to avoid this. I request you any body can solve this problem.




  8. Swaroop
    May 28, 2008 @ 1:23 am


    Very nice one which helped me a lot.

    I tried the below code for checking alphabets, hyphen and underscore. However its not working.

    Could any of you help me on this.

    function validateChars(elementValue)
    var charsPattern = /[a-zA-Z0-9_-]*/;
    return charsPattern.test(elementValue);



  9. Blaise Kal
    June 5, 2008 @ 1:58 pm

    Thanks for this. Saved me some work.

    There is a small error in the regexp: top-level domains could be longer than 4 characters (like .travel and .museum).


  10. J.Rajesh Joseph
    June 19, 2008 @ 2:43 am



  11. Mike VandeVelde
    June 24, 2008 @ 2:46 pm

    Don’t you need to escape the period? ie:


    should be:


    Otherwise, isn’t a period a single character wildcard?

    And can’t a-zA-Z0-9 be replaced with \w?

    ps Should also add apostrophe ‘ for Irish names, that’s the reason I was hunting this stuff down!


  12. Josue
    July 26, 2008 @ 7:58 am

    Thank you very much for this article. It helps me for achieving my form. In addition, your explanation is clear and light.


  13. Dario
    August 13, 2008 @ 5:36 am

    Good Job – really easy to understand explanation


  14. ray sweeten
    August 19, 2008 @ 3:50 pm

    Hey Mike,

    [a-zA-Z0-9_] can be replaced with w.

    also, because the . is included in the second character class(after @), this would be considered a valid email:


    not sure what the solution to that is. .

    .{1} does limit the repetition of . to one, but since the previous characters have already been passed, the limiter becomes irrelevant.


  15. Armando
    September 10, 2008 @ 5:53 am

    Hi Zaheer,

    Really clever solution, using regular expressions for validations.

    I am studing at uni and we covered regular expressions on our
    Unix system programing course. I see the usefulness of regular expressions now !

    Keep posting more tips 😉



  16. Matt
    January 9, 2009 @ 4:44 pm

    is a valid email address?


  17. Rossati Giovanni
    April 6, 2009 @ 2:05 am



  18. Heartburn Home Remedy
    April 15, 2009 @ 7:05 am

    Not that I’m totally impressed, but this is more than I expected for when I found a link on SU telling that the info here is quite decent. Thanks.


  19. Jim
    May 15, 2009 @ 3:12 pm

    Validate email address using regular expressions, nice piece of work. Very simple and clean. Thanks for the code. Helps me a lot.

    — Jim


  20. Gonzo
    May 31, 2009 @ 9:47 am

    This pattern isn’t a good for e-mail addresses. This pattern will filter out few of the WELL-FORMED e-mails and of MAL-FORMED as well.


  21. mr disparate
    June 17, 2009 @ 10:50 am

    gonzo: that is quite an unfounded statement. could you please give examples of both. and if you are so smart, could you show solutions also? (there is already a comment showing it accepts faulty emails)


  22. Martin
    July 2, 2009 @ 2:37 pm

    I too found that this regex has some flaws. An email like asdf@asdf would pass the filter. It doesn’t check for the .tld.

    The guys at http://www.4guysfromrolla.com/webtech/052899-1.shtml have offered this, which ensures there’s a .tld :


    I would encourage everyone to learn RegEx, it’s invaluable when you have to manipulate data, and who doesn’t these days. Zaheer’s lesson still teaches a lot.

    @Mike VandeVelde
    I believe apostrophes are illegal characters in emails.


  23. Daniel
    July 23, 2009 @ 10:11 am

    based on the above I think that:
    might be a better solution.
    w to match alphanumeric characters and underscores
    i on the end to be case insensitive
    {2,6} rather than {2,4} to cope with .museum

    this still doesn’t address .@..ww or similar though.


    Should deal with that problem though (I have not tested this fully but it works on those that I have tested which it should work on and catches those that are invalid which I tried)

    (w++*-*) matches an more than one alphanumeric followed by zero or more +s and zero or more -s
    (w++*-*)+ matches this happening at least once.
    ((w++*-*)+.?)+ matches this happening at least once with or without a . afterwards

    ((w++*-*)+.?)* is the same except that it matches 0 or more times.
    [w-]+ matches at least 1 alphanumeric character or hyphen.

    I hope this helps people.


  24. Chasalin
    August 12, 2009 @ 3:24 am

    Daniel wrote:

    Nice one!
    I tested it with something like:

    x test
    x test..@..com
    x test..@example..com
    x test..@example.example.com
    x test.2@example.com.
    v test.2@example.example.com

    (x fails, v passes)

    I used to have a script of my own that worked really nice (apart from 6-char TLD), but was about 45 lines of code…

    Zaheer and Daniel: Thank you for this huge improvement 😉


  25. Banu Channakeshava
    August 12, 2009 @ 8:04 am

    In the above test.@test.com is pass, also numerics / _ are allowed to start the email address, below regex works fine to some extent.



  26. Francisco Parada
    September 21, 2009 @ 10:08 pm

    Thanks and congratulations to Zaheer for this article: It is very well written and it is easy to read. Thanks also to the rest of people who contributed to enhance this code.

    I would like to share with you the following regex that I tried with all samples shown before (and some more, of course). I think it is worth a try:


    I think this pretty well matches a great number of e-mail addresses.




  27. Ajan
    September 22, 2009 @ 5:57 am

    Hai Latha,

    I know its a very late reply for the question which you’ve asked. Anyway let it help the users who view this forum.

    Your Question:

    “Hi can anyone help me how to invalidate the session , when i am clicking LOGOUT button. I use session.invalidate() method , the page has been expired. But when click back button on browser it goes to back page. How to avoid this. I request you any body can solve this problem.”


    response.setDateHeader(“Expires”, 0);

    just try to add the above code and check.


  28. Madhu
    November 4, 2009 @ 6:39 am

    That helped me a lot!!


  29. ashish
    November 23, 2009 @ 7:57 am

    good one..!


  30. Fabian
    January 19, 2010 @ 11:11 am

    Are mail-adresses with more than one “@” okay?
    I was just wondering. Many of the regexp allow more than one “@”. Nevertheless some regexp allow combinations like test@test@example.org ….


  31. Xin Seduction
    March 23, 2010 @ 11:37 am

    All exp failing at test:


    Any solns for it ?


  32. Bhushna
    May 6, 2010 @ 3:46 am

    Nice Post it will helps lot ,

    How can we handle multiple email’s by using comma separated.


  33. Bhushna
    May 6, 2010 @ 3:50 am

    any solution for (a@gmail.com,b@yahoo.co.in,c@gmail.com)


  34. Bhushna
    May 6, 2010 @ 4:01 am

    Hi All,
    am using this exp”” /^[a-zA-Z0-9._%-]+@[A-Z0-9.-]+.[A-Z]{2,4}(?:(?:[,][A-Z0-9._%-]+@[A-Z0-9.-]+))?$/i “”

    it’s handling this format very fine a@gmail.com,b@yahoo.co.in , while come to a@gmail.com,b@yahoo.co.in,c@gmail.com not working.

    plz help me for this req


  35. Tom Walters
    July 1, 2010 @ 7:18 am

    This is just what I was looking for, thanks very much!


  36. Dinesh
    July 2, 2010 @ 1:04 am

    Thanks. This RegEx pattern saved my day.


  37. askkuber
    July 7, 2010 @ 3:24 am

    Thanks to u Very Good Explanation of Regular Expressions

    askkuber.com TEam


  38. KrayoN
    July 26, 2010 @ 10:39 pm

    @Bhushna for you : /^[a-zA-Z0-9._%-]+@[A-Z0-9.-]+.[a-zA-Z]{2,4}(?:(?:[,][a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+))?$/i


  39. Mailpress 5.0 Email Validation Bug | Made of Everything You're Not | Eric Lamb
    August 10, 2010 @ 9:59 pm

    […] Mailpress would throw an error on the second email which was pissing of my client’s client and my client (sigh…). The fix is pretty stratightford and easy; just replace the regular expression in Mailpress with the working one I cribbed from Zaheer. […]


  40. Michael
    September 2, 2010 @ 9:56 am

    Actually if you read the relevant RFCs, pretty much any character is technically valid before the final ‘@’ sign (at least in escaped or quoted sections) – the format of that part is left completely to the receiving mail server to interpret (“Abc@def”@example.com is valid, for example). The part after the ‘@’ sign is more restrictive, because only certain characters can be used in domain names.

    You should certainly support apostrophes before the ‘@’, all but one of these regexes suggested will fail on valid email addresses like


  41. Mathew
    September 29, 2010 @ 10:36 pm

    Nice explanation.Now i really got the meaning of this regular expression.Untill now i was not known about the real meaning of this.This is nice and i thank you for the writter


  42. vasantikabade
    October 5, 2010 @ 10:31 pm

    thanx. nice explanation.


  43. Inspired
    October 6, 2010 @ 8:26 am

    Your expression does not validate Craigslist email addresses.


  44. Sasho
    November 11, 2010 @ 12:45 am

    Great, thanks for this post. It is useful for me.


  45. stryju
    November 19, 2010 @ 10:05 am


    not the best one, but works


  46. enam
    November 27, 2010 @ 1:05 am



  47. Jimmy
    December 5, 2010 @ 2:53 am

    This helped me again as i forgot the regular expression and retrieved it from your site. Thanks a lot.


  48. Sam
    December 28, 2010 @ 4:19 pm

    THANK YOU!!!
    You have no idea how many websites I have gone through to find a simple explanation of this code so I may remake it without always copy-pasting just to get the job done.
    You have helped a lot, thanks again.


  49. nithya.k
    December 29, 2010 @ 10:57 pm

    That is nice .com it’s very useful for every one thansYou for giving this website


    January 24, 2011 @ 11:15 am



  51. Pnina
    January 26, 2011 @ 3:51 am

    I noticed that you do not allow for domains such as co.uk co.il and I am sure there are others. you might want to revise…….. but thank anyway


  52. Zenonline
    January 30, 2011 @ 3:52 pm

    @Pnina, the code will work fine on co.uk domains as the regex check after the “@” sign allows multiple periods (“.”) to be there (this allows for subdomains to be allowed as well) so as long as the last set of digits after the period are 2-4 digits long the validation will work


  53. ruby
    February 1, 2011 @ 2:09 pm

    It allows Testyahoo@yahoo..om , if we type two dots , it is validating as true.


  54. Rca Ieftin
    February 18, 2011 @ 6:27 am

    I didn’t know that you can validate the email address using JavaScript regular expression. I suppose it’s the best option if you need to validate in a easiest way this task.


  55. ifti
    March 16, 2011 @ 3:23 am

    its not working n its allow String “r@#$” if i take only “[a-zA-Z0-9._-]+” as a patten;


  56. expert
    March 20, 2011 @ 6:40 am

    this one won’t work with a+b@g.com, right?


  57. Spiderman
    May 4, 2011 @ 12:49 pm

    Use this regex instead



  58. Confused
    May 24, 2011 @ 4:20 am

    This just returns the value of the email you pass it? It dosen’t result in a true/false test? How is this of any use?


  59. Meserias
    May 24, 2011 @ 8:19 am

    ATENTION: this regex has a bug. The right syntax is:

    Without this modification a string like name@yahoo is a valid emalil address.

    for Confused: this function return true if the user type a valid email address (name@domain.extension) and false if not.
    You can call the function in this way:
    var valid_email=validateEmail(document.getElementById[‘field_id’].value);
    if(valid_email){ [your code] }else{ [your code] }
    This validation is for you users, but you must do another validation on server side when you save your data.


  60. Mudassar Mumtaz
    June 4, 2011 @ 12:09 pm

    these are easy expressions to understand and aplliying…really i like it a very much.


  61. Deepak Agg
    June 9, 2011 @ 6:52 am

    function val()
    var email = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+[.]{1}[a-zA-Z]{2,4}$/;
    alert (“plz enter tha email”);
    return false;



  62. Tank
    June 17, 2011 @ 9:15 am

    I modified this a bit to allow sub domains, multiple tld’s and removed validating multiple .’s (user@domain..com)
    will validate abc@domain.co.uk, abc@domain.com.tw, abc@sub.domain.co.uk


  63. wew
    July 13, 2011 @ 1:28 am



  64. Jasmine
    July 19, 2011 @ 4:19 am

    This email validation script is awesome, although I replaced it with Meserias’ modification. Thanks for the script!


  65. Maddie
    August 3, 2011 @ 12:58 pm

    Actually Maserias’ modification works really well except that it accepts abc@.xyz.com. “@.” shouldn’t be together. I made a minor modification to it:

    So this checks to see that the domain starts with alphanumeric characters. The credit however goes to Meserias!


  66. mahesh
    August 6, 2011 @ 1:00 pm

    gr8….easy to understand and implement


  67. John K
    August 13, 2011 @ 6:12 pm

    Maddie’s regular expression doesn’t recognize a@b.com (exactly one character between ‘@’ and ‘.’. This modification corrects this problem:



  68. Jerry
    August 21, 2011 @ 6:33 pm

    It’s a pet peeve of mine that people publish regular expressions for email addresses when they simply don’t know the standard. Every single regular expression on this page, article and comments alike, fails to validate email addresses of the form joe+list@domain.com (though to be honest I didn’t check all the older comments). People grab these expressions and throw them into their code, thinking that will make them fit some sort of standard, when they don’t.

    The inability to add the +suffix to an email address undermines the usefulness of the feature even where it is accepted. PLEASE add proper support for the standard and spread the word.

    There’s a good article at http://www.regular-expressions.info/email.html that discusses tradeoffs of various regular expressions for validating email addresses.

    On this form I’m using a + sign in my email address.


  69. khaiknievel
    August 26, 2011 @ 2:14 am

    use this . from jquery.validate.js => no, its not, the longer the better. this just works



  70. DisFanJen
    September 3, 2011 @ 6:50 am

    Thanks this is a simple and elegant solution to the problem.

    Also thanks to Tank. I found his modification to the expression to be the best for my needs. 🙂


  71. kumar
    September 8, 2011 @ 11:11 pm

    not bad


  72. iftikhar
    September 21, 2011 @ 10:25 pm

    thanx i got alot from this


  73. sampath
    October 3, 2011 @ 12:50 am

    I used this expression and worked well.


    As a Java String


    Of-course the length part of the email is not considered in the regular expression.

    This will allow ! # $ % & ‘ * + – / = ? ^ _ ` { | } ~ in the local part and the local part can end with dot (.)

    domain part can be IP or domain


  74. ibna
    October 3, 2011 @ 8:14 am

    greetings ..

    i just want to know does this regex check dot at the beginning of email id because as per the expression we can have dot and digits at the start as well like for example:


    Are these id’s valid?? please brief on that ..



  75. Joby Chacko
    October 28, 2011 @ 5:00 am

    fantastic!!!!!!!. Thanks for this simple solution.


  76. henru
    November 8, 2011 @ 6:14 am

    how can we make the expression for a specific mail like gmail


  77. z666zz666z
    November 17, 2011 @ 8:24 am

    To end on “@gmail.com” just use this as final part:


    If want to check anything before @ add checks at begining.

    This one will only allow leters, numbers and ‘_’ and ‘-‘ as left part of @ and must be on gmail.com


    An this other one is also to accept dot on user part, but not at start neither near the @:


    Hope helps!


  78. rabia
    November 23, 2011 @ 7:22 am

    good 🙂


  79. hak
    November 24, 2011 @ 2:59 am

    what if someone inputs ‘joe@support.com.com’

    or @.edu.edu



  80. Multiple email
    December 13, 2011 @ 5:29 am

    This RegEx allows multiple email addresses if it is separated by a “;”
    In a textbox if i need to validate a single email address and if two addresses are entered then this RegEx wont work.


  81. Mardi
    December 15, 2011 @ 3:19 am


    I am VERY new too Javascript and need to validate a form for a tafe assignment. So far I have added code to validate required text fields and a drop down menu and have all the error messages come up in the one alert box. Now I am having trouble figuring out how to add the code to validate an email and have the error message appear in the same alert box as they are other fields are being validated. I hope I am making sense!!

    If anyone is able to help this is my code! Please ignore all the comments! I have to add them as parrt of the assignment

    function checkforblank() {

    var errormessage = “”;

    if (document.getElementById(‘selectmenu’).value == “”) {
    /* the getElementById is determined by the id given in the below html.
    For example: */
    errormessage += “Please specify your title n n”;
    document.getElementById (‘selectmenu’).style.borderColor = “red”;
    /* .style.borderColor highlights the borders of the text fields in red when there is an error */
    if (document.getElementById(‘fname’).value == “”) {
    errormessage += “Please enter your first name n n”;
    /* error message if first name field is not filled out */
    document.getElementById (‘fname’).style.borderColor = “red”;
    if (document.getElementById(‘lname’).value == “”) {
    errormessage += “Please enter your last name n n”;
    /* error message if last name field is not filled out */
    document.getElementById (‘lname’).style.borderColor = “red”;
    if (document.getElementById(‘enquiry’).value == “”) {
    errormessage += “Please submit an enquiry n n”;
    /* error message if viewer does not enter an enquiry */
    document.getElementById (‘enquiry’).style.borderColor = “red”;
    if (errormessage != “”) {
    alert (errormessage);
    /* alert (errormessage) displays the specified error messages that were created in the
    above if statements */
    return false;
    /* return false stops the form from being submitted to the server */
    // End of function



  82. Jeremy Johnstone
    December 16, 2011 @ 11:31 am

    This regex has so many flaws I have to heavily recommend everyone ignore it. Worse than the numerous false positives others have already pointed out, it also regexs common perfectly valid email addresses. For example, the + character is very valid and not super uncommon in the left hand side of an email address.

    Buyer beware, you get what you pay for when you use this regex!


  83. John K
    December 31, 2011 @ 2:29 pm

    here’s the regex modified to accept + signs after the first character of the address:


    I also shortened it by adding i modifier at end, so don’t need to specify A-Z for uppercase letters. The regex still has false positives, no doubt, but no false negatives for + signs.


  84. Rashid
    January 22, 2012 @ 1:57 am

    ya zaheer paratha koon ha?????


  85. Tory
    January 24, 2012 @ 12:13 pm

    The solution Tank gave seems to pass all my tests and it’s a one liner. Thanks Tank


  86. Kent
    February 2, 2012 @ 3:27 pm

    Does Tank’s address a+anything@gmail.com? It did not seem too. Jerry mentioned this.

    This is a feature at gmail, add a “+(anything you pick)” before the @ on your regular gmail address, and the email will still be delivered to you, but you can send it to special filters.

    Modifying Tanks to this

    Seemed to work.


  87. dinus
    February 8, 2012 @ 9:09 am

    can some one please explain the meaning of below regular expression :

    thanks in advance


  88. Neelaka
    February 13, 2012 @ 10:56 pm

    thank you for helping to validate e-mail


  89. ram
    February 14, 2012 @ 7:42 am

    elseif($_POST[‘name’]==eregi(‘^[a-zA-Z ]+$’)) is correct


  90. ganesh123
    February 14, 2012 @ 7:44 am

    error in eregi(‘^[a-zA-Z ]+$’))


  91. daisy
    February 27, 2012 @ 1:19 am

    I want upload pdf book from any location in the PC to specific folder and save this path in mysql. With possibility of download this book.And when I want delete this PDf from the sit this PDf also delete from the folder and its path from the mysql .Please help me.


  92. Venu
    March 2, 2012 @ 1:17 am

    Hi I need a code.I have ONE text box.When i am filling the text box,First letter should be alphanumeric and last 4 should be numbers.Give me replay ASAP.


  93. compzets
    March 3, 2012 @ 3:23 am

    gud post buddy


  94. Alito
    March 3, 2012 @ 5:32 pm

    Very helpful!


  95. Lightning
    March 30, 2012 @ 6:30 am



  96. Abdul Wahab Qambrani
    April 3, 2012 @ 9:28 am

    Very Informative and Helpful code. specially learners and beginners.



  97. Andrea
    April 9, 2012 @ 12:41 am

    Thanks everyone for your contributions.
    I went with Tank’s solution and Kent’s modification. Does the trick for me!~


  98. Mohamed Alaa
    April 9, 2012 @ 1:24 pm

    I’m using this and it’s working perfect:

    mailRegex = /[a-z0-9!#$%&’*+/=?^_`{|}~-]+(?:.[a-z0-9!#$%&’*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])/;

    This will help you validating wrong emails including: name@sample..com

    Best Regards,


  99. Darryl Young
    April 17, 2012 @ 8:38 am


    I’m glad I came across this thread and I hope I can get some help off you guys! I’m trying to work with an previously written JavaScript function to validate an email but it’s having problems if the user enters a space at the end of their email address (it happens, especially on mobile with auto-complete etc). How could I amend the following code to allow a space at the end?

    function checkMail(emailInput) {
    filter = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
    if(!filter.test(document.lpform.email.value)) {
    return false; }
    return true;

    Thanks so much! I really appreciate it. =D


  100. Darryl Young
    April 19, 2012 @ 4:56 am

    Ok, I just added s and that worked…

    filter = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Zs]{2,4}$/;

    Thanks anyway.


  101. John
    May 1, 2012 @ 8:19 am

    Hello All,

    I am Glad that i have landed to this email. I have a new requirement for validating email for a new format, can anyone tell me how to by pass.


    I tried removing / from the below exemplist, But the code is throwing JS error.

    var exemplist =/^[a-zA-Z][w.-]*[a-zA-Z0-9]*@[a-zA-Z0-9][w.-]*[a-zA-Z0-9]*.[a-zA-Z][a-zA-Z.]*[a-zA-Z]$/

    Thanks in advance.


  102. jagadeesh
    May 14, 2012 @ 9:32 am

    very nice content it is very useful to me.


  103. naveen
    May 25, 2012 @ 1:03 am

    fgsdf gsdfg