RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
(\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})
Description
This is my all-time favourite e-mail validator. I've used it for years and it's never failed me :-)
Matches
foo@bar.com | foobar@foobar.com.au
Non-Matches
foo@bar | $$$@bar.com
Author Rating: The rating for this expression. Darren Neimke
Source
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Nowhere near RFC822 compliant
Name: Scott Tadman
Date: 8/6/2010 10:46:42 AM
Comment:
This is a really naive and incorrect implementation of the RFC822 specification on what an email address can contain. Gmail, as a simple example, permits names like example+name@gmail.com which will fail here. There are also top-level domains with more than three letters including ".info" and ".name" which have been around for years. It's woefully inadequate regular expressions like this that infuriate users and kill your sign-up rates.' Although the full regexp is rather unwieldly (http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html) you should at least be more generous than this.


Title: web admin
Name: frank wright
Date: 2/9/2005 11:11:22 AM
Comment:
this is good but you need to match the last bit with the end of the line \w{2,3}$


Title: Fails to match valid email address
Name: The Fred and Barney Comedy Team <fred&barney@stonehenge.com>
Date: 1/26/2005 3:37:35 AM
Comment:
Fails to match the valid email address fred&barney@stonehenge.com


Title: Don´t discriminate other TLDs!
Name: Sascha
Date: 1/22/2005 7:22:48 AM
Comment:
This REGEX is not completely correct, as it does not allow any of the following top level domains: - .info - .museum - .aero - .coop - .name See http://www.iana.org/gtld/gtld.htm To correct this simply change {2,3} at the end to {2,6} but keep in mind that there might even be longer domains sometime!


Title: Not 100%
Name: Oscar
Date: 1/12/2005 8:17:50 AM
Comment:
This one does not allow for example .info-domains. It only allows 2 or 3 letters in the top-domain.


Title: didi not work
Name: david
Date: 12/8/2004 6:56:13 AM
Comment:
this reg exp did not work for my purpose


Title: Here is one that doesn't work
Name: Eric
Date: 7/8/2004 10:43:57 AM
Comment:
This address doesn't work: john.doe@[255.008.09.090] Here is one that seems to work great. Yes, it's a bit long. Matches: john@doe.com, john.doe@[255.008.09.090], john-doe.i.am@john-doe.i.am.com ([a-zA-Z0-9_\-])+(\.([a-zA-Z0-9_\-])+)*@((\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))\]))|((([a-zA-Z0-9])+(([\-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([\-])+([a-zA-Z0-9])+)*))


Title: A+ BS MCSE Web Developer
Name: PersistentMF
Date: 5/6/2004 3:11:10 PM
Comment:
Darren: Thank you. I am moving away from ColdFusion Javascript & writing my own. The first form that I redid eliminated 40% of the code. It's hard to find all the answers in the same place, but your expression tersely illuminated more things that you can do with RegExp. :)


Title: 4 character TLDs
Name: torbjorn.thorsen@erbeco.no
Date: 4/20/2004 6:43:22 AM
Comment:
Will this work with .info domain? .. I was looking at the last instruction of your regex, and the {2,3} seems to me to be restricting the TLD of the e-mail adress to maximum 3 characters ?


Title: Soft. Developer
Name: pritam
Date: 4/5/2004 9:30:20 AM
Comment:
nice results with this email validation reg. expr.


Title: my modifications
Name: Rob Eberhardt
Date: 1/20/2004 7:54:04 AM
Comment:
not bad. my modifications: /^(\w([-._\w]*\w)*@(\w[-_\w]*\w\.)+\w{2,9})$/ It allows usernames that are 1 or two \w characters, or 3 plus can have -._ between \w characters. It more strongly enforces the domain name pattern, allowing it to be repeated (e.g. @really.big.com). It allows 9 character alphabetic-only TLDs (that oughta cover museum and adnauseum :>). Finally, it wraps it up in input start/end characters, to catch invalid junk around a valid address.


Title: Domain extensions can be more than 4 characters
Name: Jason Haymer
Date: 9/2/2003 2:00:54 PM
Comment:
In response to Kevin's comment which contained: "Also ".com" extensions are always alpha-characters[a-z], and are between 2 to 4 chacaters long, such as .uk or .com. The 4 is there because I've heard(but not seen) that .info is going to be coming out soon." ... In fact they can be longer - ICANN recently took the bizarre step of introducing .museum domains e.g. cambridge.museum . And .info, .aero, .coop etc have been around since 2001. I notice that many email regexps in this site ignore these facts.


Title: Re: It's not perfect however
Name: Darren Neimke
Date: 8/31/2003 7:09:49 PM
Comment:
Ted, It does match on "tt@tt@ta.ca" if you don't put a 'beginning of line' anchor at the start like so: ^\w[-._\w]*\w@\w[-._\w]*\w\.\w{2,3})$ In your example the *actual* matched bit of text is: tt@ta.ca NOT the full input string!


Title: I'm using Darren's...
Name: Nobody You Know
Date: 8/27/2003 8:43:36 PM
Comment:
... in a slightly modified form (7-letter TLD max. vs. 3) because you don't have to be an ubergeek to make it work with JavaScript's replace() method. :)


Title: Kevin
Name: re-direct
Date: 8/14/2003 3:07:29 PM
Comment:
There is/was another discussion going on. Looks like there are better ones out there. http://www.regexlib.com/REDetails.aspx?regexp_id=26


Title: sorry but...
Name: Kevin
Date: 8/14/2003 2:32:24 PM
Comment:
It won't match 'tt@tt@ta.ca', I just tried. Here is the differences between yours and Mine. All domains must start and end with a-z or 0-9, the \w is equivelent to [A-Za-z0-9_] <-- as you can see there is an underscore in there, and domains and emails can't start or end with an underscore. Also ".com" extensions are always alpha-characters[a-z], and are between 2 to 4 chacaters long, such as .uk or .com. The 4 is there because I've heard(but not seen) that .info is going to be coming out soon. Mine will reject and yours will accept: _kevin@yahoo.__ , Kevin@msn_.com I wrote mine to be very strong, and yours in a little less strict. That is all I'm trying to say, I might reject a valid email, but I can't think of a valid one that would be rejected.


Title: RE: Better?
Name: Max Nokhrin
Date: 8/14/2003 11:05:17 AM
Comment:
Yes, it's better because it doesn't allow for xxx@xxx.000


Title: It's not perfect however
Name: Ted Kerkelis
Date: 8/13/2003 4:15:06 PM
Comment:
It allows tt@tt@ta.ca


Title: Better?
Name: Kevin
Date: 8/13/2003 10:30:49 AM
Comment:
^[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z]{2,4}$ I think this one is better, but thats just me, its just a little stronger rules


Copyright © 2001-2014, RegexAdvice.com | ASP.NET Tutorials