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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Email
Expression
^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$
Description
regex to validate email address noteworthy: (1) It allows usernames with 1 or 2 alphanum characters, or 3+ chars can have -._ in the middle. username may NOT start/end with -._ or any other non alphanumeric character. (2) It allows heirarchical domain names (e.g. me@really.big.com). Similar -._ placement rules there. (3) It allows 2-9 character alphabetic-only TLDs (that oughta cover museum and adnauseum :>). (4) No IP email addresses though -- I wouldn't Want to accept that kind of address.
Matches
e@eee.com | eee@e-e.com | eee@ee.eee.museum
Non-Matches
.@eee.com | eee@e-.com | eee@ee.eee.eeeeeeeeee
Author Rating: The rating for this expression. Rob Eberhardt
Source loosely based on http://regexlib.com/REDetails.aspx?regexp_id=356
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: Hangs(unresponsive) for long expressions which ends with space.
Name: Vinayaka
Date: 10/1/2012 6:55:38 AM
Comment:
The regex hangs for long expressions which ends with space. EX: dddddddddddeeeeeee123@dddd.com (space at the end is necessary to make the regex unresponsive.)


Title: Hangs(unresponsive) for long expressions which ends with space.
Name: Vinayaka
Date: 10/1/2012 6:54:43 AM
Comment:
The regex hangs for long expressions which ends with space. EX: dddddddddddeeeeeee123@dddd.com (space at the end is necessary to make the regex unresponsive.)


Title: C# email validation
Name: Welbre
Date: 2/22/2012 12:28:01 PM
Comment:
You can validate email in c# like this pattern = "^([0-9a-zA-Z]([-\\.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$"; Regex.IsMatch("feedback@net-informations.com", pattern) http://net-informations.com/csprj/communications/validate-email.htm well.


Title: C# email validation
Name: Welbre
Date: 2/22/2012 12:27:30 PM
Comment:
You can validate email in c# like this pattern = "^([0-9a-zA-Z]([-\\.\\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,9})$"; Regex.IsMatch("feedback@net-informations.com", pattern) http://net-informations.com/csprj/communications/validate-email.htm well.


Title: Vulnerable to Denial of Service attacks!
Name: Abe
Date: 10/26/2010 11:16:06 AM
Comment:
This regex is vulnerable to regular expression denial of service attacks. Take a look here: http://www.abemiester.com/abemiester/post/RegEx-DOS-attack-Regular-Expressions-Now-you-have-3-problems.aspx


Title: Following expression allows one letter, it seems...
Name: James Khouri
Date: 6/27/2010 2:20:13 PM
Comment:
Hey, forgive me if I'm doing something wrong. I don't appear to be. But please test this. The following expression seems to allow me to simply type the letter 's' (without quotes) and it submits: ^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,9})$


Title: RetEx vulnerable for DoS Attacks
Name: Wesen
Date: 5/14/2010 2:34:39 PM
Comment:
if executed in NFA type of Regex engine can be used for DoS attacks. read the article from Bryan Sullivan (MSDN Magazine May 2010, page 82).


Title: Precarious nested quantifiers
Name: Niki H.
Date: 10/7/2009 10:55:49 AM
Comment:
All in all this regex would make a pretty decent job... if there weren't cases which will cause the Engine to hang. My computer is trying to validate the address 'gbounce-3561586842-3534-352365876-1254920235325@bounce.e.hotelplan.nl' for about 1.5 hours already, and no end is in sight. Read more about the problems with nested quantifiers here: http://blogs.msdn.com/tess/archive/2007/10/25/net-hang-case-study-high-cpu-because-of-poorly-formatted-regular-expressions-identifying-tight-loops.aspx Thanks for this regex but be careful with it in a production environment. ;-)


Title: Regex for multiple email id
Name: Harsh Bandlish
Date: 2/19/2009 1:32:27 AM
Comment:
([a-zA-Z0-9_\.!$&*\-=^`|~#%'+/?_{}]+@[a-zA-Z\.!$&*\-=^`|~#%'+/?_{}]+[\.]+[a-zA-Z]+){1}([;]+[\s]*([a-zA-Z0-9_\.!$&*\-=^`|~#%'+/?_{}]+@[a-zA-Z\.!$&*\-=^`|~#%'+/?_{}]+[\.]+[a-zA-Z]+))*


Title: Regex for multiple email id
Name: Harsh Bandlish
Date: 2/19/2009 1:31:50 AM
Comment:
([a-zA-Z0-9_\.!$&*\-=^`|~#%'+/?_{}]+@[a-zA-Z\.!$&*\-=^`|~#%'+/?_{}]+[\.]+[a-zA-Z]+){1}([;]+[\s]*([a-zA-Z0-9_\.!$&*\-=^`|~#%'+/?_{}]+@[a-zA-Z\.!$&*\-=^`|~#%'+/?_{}]+[\.]+[a-zA-Z]+))*


Title: email reg ex
Name: chetan
Date: 12/19/2006 5:05:58 AM
Comment:
It does not work when manager@abcdefg.com and manager_ge 2yahoo.com is given.its buggy


Title: Last updates?
Name: Earl
Date: 10/25/2006 11:15:56 AM
Comment:
Has this regex been updated or used recently - and how well does it work? It seems pretty robust but just curious what people are seeing that are using it. Thanks.


Title: Corrected Version for not Missing single letter subsdomain recognition
Name: Peter Lee
Date: 4/18/2006 7:35:43 AM
Comment:
^([0-9a-zA-Z]\.|([0-9a-zA-Z][-\w]*[0-9a-zA-Z])\.)+[a-zA-Z]{2,9}$ is this right?


Title: Randall
Name: Rob Eberhardt
Date: 2/16/2005 1:05:18 PM
Comment:
Strange coincidence... For those of you wanting the regex behemoth necessary for RFC822, I just stumbled on this: http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html (via http://www.codinghorror.com/blog/archives/000214.html) Enjoy all 6.2KB, Randall!


Title: Randall
Name: Rob Eberhardt
Date: 2/16/2005 12:48:42 PM
Comment:
I'd love to use an elegant regex that nails all 40 pages of the RFC. Hop to it Randall!


Title: No clue about valid email
Name: Randal L. Schwartz
Date: 2/16/2005 9:37:41 AM
Comment:
You say: (1) It allows usernames with 1 or 2 alphanum characters, or 3+ chars can have -._ in the middle. username may NOT start/end with -._ or any other non alphanumeric character. You really *don't* have a clue about valid email addresses do you? Ever read RFC822? I guess not.


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


Title: Bug?
Name: Silvery Cat
Date: 1/12/2005 3:48:50 AM
Comment:
Validate as correct expression like "andrew..1@smth.com" (two or more dots before "@"). Seems just weird to me.


Title: Read his description
Name: ceph
Date: 7/28/2004 12:27:45 PM
Comment:
Read his description, it doesn't accept IP-based emails. Nor should anyone... get a fricken domain.


Title: .
Name: HD
Date: 7/14/2004 3:07:05 AM
Comment:
Validation Fails when you type johncitizen@123.56.26.56


Title: Missing asterisk
Name: Gorka
Date: 7/12/2004 6:54:41 AM
Comment:
Nice regexp, but didn't you miss an asterisk in the domain part? ^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@([0-9a-zA-Z][-\w]*[0-9a-z A-Z]*\.)+[a-zA-Z]{2,9})$ seems more like it for me.


Title: works for me
Name: Rob
Date: 7/2/2004 4:22:52 PM
Comment:
RegExpLib's regular expression tester says "There were 1 matches" for blue@martini.com with this regex. Perhaps your regex javascript is what's not working. Try it: http://www.regexlib.com/RETester.aspx?regexp_id=541


Title: in javascript
Name: crodri1
Date: 7/2/2004 3:45:08 PM
Comment:
I am attempting to use this regular expression in javascript and it is not working if the domain is longer than 5 characters. i.e. blue@martini.com


Title: In C#
Name: joe
Date: 7/1/2004 2:34:02 PM
Comment:
To correct the escape sequence problem try putting "@" just before the string open quote to tell the compiler that your string contains "un-escaped" characters. Like this... Regex r = new Regex(@"^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA -Z]{2,9})$");


Title: Using it under c#
Name: email
Date: 4/22/2004 10:57:48 AM
Comment:
Hi, I´m a beginner with the regular expresions. And I would like to know, if anybody can help me, how i can test it under c# in visual studio .net 2003. I´ve tried this with no success: Regex r = new Regex("^([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})$"); Doing it i get an error at the moment of compiling because the escape secuence is not known. Thanks


Title: yeah
Name: Rob Eberhardt
Date: 2/25/2004 4:32:24 PM
Comment:
yeah, i guess so. it's supposed to prevent single letter domain names, and since it reuses the same for subdomains, they're caught too. I don't want to relax the domain restriction, so I see no simple solution short of rewriting the subdomain check separately...


Title: Missing single letter subdomain recognition
Name: Shaune Stark
Date: 2/25/2004 3:48:14 PM
Comment:
This RegEx fails to match an address like aaa@b.ccc.com!


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