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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.+)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$
Description
It verifies that: - Only letters, numbers and email acceptable symbols (+, _, -, .) are allowed - No two different symbols may follow each other - Cannot begin with a symbol - Ending domain must be at least 2 letters - Supports subdomains - TLD must be between 2 and 6 letters (Ex: .ca, .museum) - Only (-) and (.) symbols are allowed in domain, but not consecutively. Problems: See comments below
Matches
g_s+gav@com.com | gav@gav.com | jim@jim.c.dc.ca
Non-Matches
gs_.gs@com.com | gav@gav.c | jim@--c.ca
Author Rating: The rating for this expression. Gavin Sharp
Source Gavin Sharp (http://www.glensharp.com/gavin/)
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: Minor fix
Name: Avishay Cohen
Date: 1/10/2012 11:32:03 AM
Comment:
Minor fix - dot(.) is not allowed to appear two or more times consecutively (see http://en.wikipedia.org/wiki/Email_address ) So \.+ turned to \. And this is the one with the fix: ^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$


Title: Minor fix
Name: Avishay Cohen
Date: 1/10/2012 11:31:47 AM
Comment:
Minor fix - dot(.) is not allowed to appear two or more times consecutively (see http://en.wikipedia.org/wiki/Email_address ) So \.+ turned to \. And this is the one with the fix: ^(([A-Za-z0-9]+_+)|([A-Za-z0-9]+\-+)|([A-Za-z0-9]+\.)|([A-Za-z0-9]+\++))*[A-Za-z0-9]+@((\w+\-+)|(\w+\.))*\w{1,63}\.[a-zA-Z]{2,6}$


Title: Great work!
Name: Juan McClore
Date: 6/29/2010 1:15:47 PM
Comment:
I am testing this good. Admittedly, I did not set the other tests up the same, but I am so happy with this one, I don't need to search any further. By setting it up I mean utilizing the match operator the way I should have on the others I tested; i.e. m//. Anyone familiar with Perl should already know this, but I am familiar and I did not do it at first! So there you go ...


Title: Doesnt match dash at the end
Name: KnaveT
Date: 3/3/2010 8:30:57 PM
Comment:
Doesn't match new emails like "somename-@hotmail.com". Here's my updated expression to support this and also the underscore. ^[A-Za-z0-9](([_\.\-]?[a-zA-Z0-9]+)*)((|\-)*)@([A-Za-z0-9_]+)(([\.\-]?[a-zA-Z0-9_]+)*)\.([A-Za-z]{2,})$ Validates: jasmine-@hotmail.com jasmine--@hotmail.com bad@example_example.com


Title: Not working
Name: Nick Gilbert
Date: 11/3/2009 6:37:02 AM
Comment:
Doesn't work... doesn't permit many basic email addresses like michael.o'leary@ryanair.com I have dozens of users with apostrophies in their email address (mainly for o'brien)


Title: Using Ruby, matches 'bad@example_example.com'
Name: Asfand Yar Qazi
Date: 3/27/2009 11:42:59 AM
Comment:
Hi, I'm using Ruby on Rails, and this expression should not match 'bad@example_example.com', but it does. I don't know if this is a Ruby thing, but just letting other Rubyists know.....


Title: RE:Doesn't matches comma separated multiple email addresses
Name: Anarud
Date: 3/26/2009 2:11:53 PM
Comment:
Rohit, IMHO, the idea of a regex is to validate or otherwise match a single (emphasis on single) thing at a time. Although your idea is good in theory, in practice you'd do better using an Array or any other type of collection to gather all those e-mail addresses and validate them one at a time. Best regards, Anarud.


Title: RE:Doesn't matches comma separated multiple email addresses
Name: Anarud
Date: 3/26/2009 2:11:52 PM
Comment:
Rohit, IMHO, the idea of a regex is to validate or otherwise match a single (emphasis on single) thing at a time. Although your idea is good in theory, in practice you'd do better using an Array or any other type of collection to gather all those e-mail addresses and validate them one at a time. Best regards, Anarud.


Title: Doesn't matches comma separated multiple email addresses
Name: Rohit
Date: 11/3/2008 1:27:35 AM
Comment:
Hi, i used this and is working good for single emails. but isn't working for multiple email separated by ';' or ','. Any idea about this?


Title: Is it a bug?
Name: Scylla
Date: 4/18/2007 3:03:23 AM
Comment:
Helle, the email " I_am_@domain.com " doesn't macth


Title: Is it a bug?
Name: Scylla
Date: 4/18/2007 3:03:08 AM
Comment:
Helle, the email " I_am_@domain.com " doesn't macth


Title: The best e-mail validating regex
Name: Ian Dunn
Date: 10/19/2006 11:34:38 AM
Comment:
I got frustrated with all the incomplete e-mail validating regex's out there and setup a test to try and find the best. So far this one validate's everything it should and only a few that it shouldn't: ^([a-zA-Z0-9_'+*$%\^&!\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9:]{2,4})+$ More details are here: http://fightingforalostcause.net/misc/compare-email-regex.php


Title: Misses severlal legal variations
Name: The old pedant
Date: 12/2/2005 4:45:44 PM
Comment:
Misses "Joe's fish market"@[111.222.33.255] just for example. Okay for most cases.


Title: sorry - not all chars allowed
Name: michl
Date: 9/22/2005 9:57:53 AM
Comment:
hm... test it: jürgen.müller@web.de [german name] >> ü is an allowed char. but you regex say no! >> ÄäÖöÜüß


Title: Can't enter work name sep by dots
Name: Nancy Steinmann
Date: 4/13/2005 5:53:30 PM
Comment:
This regex doesn't seem to work properly for validating email addresses such as those used by my business, i.e., firstname.mi.lastname@domain.com.


Title: KILL THE root@localhost
Name: REBILLGOON
Date: 4/9/2005 7:30:01 AM
Comment:
CHECKOUT THIS. (?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*")(?:\.(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|"[^\\\x80-\xff\n\015"]*(?:\\[^\x80-\xff][^\\\x80-\xff\n\015"]*)*"))*(?:\.)?@(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\])(?:\.(?:[^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff]+(?![^(\040)<>@,;:".\\\[\]\000-\037\x80-\xff])|\[(?:[^\\\x80-\xff\n\015\[\]]|\\[^\x80-\xff])*\]))+


Title: "#" is a valid email character per RFC
Name: Jake
Date: 3/22/2005 4:49:14 PM
Comment:
FYI, "#" is a valid email address character. unfortunately. Although not recommended because of it's conflicting role in many MTA configs (as a comment char), it definitely needs to be allowed.


Title: Sir Nate
Name: Nate
Date: 3/22/2005 4:45:22 PM
Comment:
# is a valid char as well, FYI.


Title: No match on valid email
Name: Matt Witt
Date: 3/19/2005 7:14:59 AM
Comment:
Doesn't match foo_foo_@hotmail.com whish is valid


Title: PHP - ereg and preg_match
Name: MMutt
Date: 3/14/2005 1:41:27 AM
Comment:
this had some good comments and a good rating, but it didn't work in some php scripts i've been working on. i tested it using this site's reg ex testing tool. it failed to match the above sample matches. if someone has a good email validation regex that'll work with those php functions, please submit it! ;) thx


Title: Regular Expression Details
Name: vijay
Date: 2/28/2005 7:50:07 AM
Comment:
ok type


Title: Wonderful
Name: Gavin Sharp
Date: 2/17/2005 10:41:53 PM
Comment:
Thanks for the insight. Since you know so much about valid email addresses, I'm sure you meant to say "Please read RFC 2822", since it has superseded RFC 822. As I've stated before, feel free to develop you're own RegEx if you find this one insufficient. It is almost two years old now, and I've moved on. I fail to see how posting some vague remark like "go read the RFC" benefits anyone.


Title: NO CLUE ABOUT VALID EMAIL
Name: Randal L. Schwartz
Date: 2/16/2005 9:38:34 AM
Comment:
you say: Only letters, numbers and email acceptable symbols (+, _, -, .) are allowed YOU HAVE NO CLUE ABOUT A VALID EMAIL ADDRESS. Please read RFC822.


Title: Apostrophy
Name: Rob
Date: 2/10/2005 1:42:37 PM
Comment:
This regex doesn't appear to support apostrophies (as in "john.o'brien@email.com"). I believe they are perfectly legal in email addresses as I have seen several working emails with them. This is easy to fix, however.


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


Title: Good Regex, syntax and validity are two different things
Name: John Sinclair
Date: 1/17/2005 10:44:55 AM
Comment:
Checking syntax and checking validity are two different tasks. This regular expression does an excellent job of accepting many of the weird things allowed by RFC 3696 on the left-hand side of the 'at' symbol. For example, $%^%JidO_kdoe*&&2@lkd.vfg is syntactically valid, also single and double quotes may fall on the left side. The left side is not as structured as the right side. On the right side, a domain such as acid@stardust-studios.net.com.co.uk.au.us.museum.info.org is syntactically correct. However it isn't valid. To discover its validity we would use another function. In php a function such as checkdnsrr() sees if there exists a DNS record for such a domainname. To go a step further, in php we can gather all the MX records (mailboxes) at that domain then scan for a mailbox called as 'acid'. Gavin's regex is very good as it stands.


Title: don't work with all email address
Name: Fab
Date: 1/4/2005 4:56:54 AM
Comment:
The regex does not work with e-mail address like xxx_@domain.com


Title: mixing [a-zA-Z0-9] and \w ?
Name: Satan
Date: 12/6/2004 4:28:19 PM
Comment:
Aren't they the exact same thing ? If so, shouldn't it be consistent ? Nice regex though.


Title: Thanks
Name: Gavin Sharp
Date: 8/24/2004 1:10:58 PM
Comment:
Thanks for the heads up, I appreciate it. I am however not really maintaining this anymore. It does have some issues, as mentioned above, but for my limited use it works well enough. Although it may not catch some of the technically valid addresses, I think it does a much better job of validating than some of the other regular expressions on this site. For people with stricter requirements, this may be too limited. Feel free to use any of the other regular expressions.


Title: False Negative
Name: Kiril
Date: 8/24/2004 12:42:54 PM
Comment:
This should return as valid: $%^%JidO_kdoe*&&2@lkd.vfg This address (from RFC3696 Section 3 example) should also validate, but doesn't: !def!xyz%abc@example.com I'm sure there are more examples that will fail.


Title: Not an error
Name: Gavin Sharp
Date: 7/16/2004 5:05:18 PM
Comment:
Two consecutive dots are valid in email addresses (if you want proof, email gav..gav@glensharp.com and I'll reply).


Title: Error
Name: Josef
Date: 7/16/2004 4:35:50 PM
Comment:
Matches: foo..foo@foo.foo


Title: Mathes too long urls...
Name: Rudy
Date: 3/23/2004 6:33:13 AM
Comment:
you can have a longer than 63 character match by using the hypen to defeat your regex.... example: rudy@asdfasdf-asdfasdf-asdfasdf-asdfasdf-asdfasdf-asdfasdf-asdfasdf-asdfasdf-asdfasdf-.com


Title: New Changes
Name: Gavin Sharp
Date: 12/23/2003 3:54:05 AM
Comment:
RE: Multiple TLDs The example you give is a syntaxically valid address, therefore this expression matches it. RE: Skilla I've added a limit of 63 characters for the domainname. Be aware that for certain TLDs, a single letter extension is valid (ex: http://www.e.dk/ ).


Title: Above email address is valid ...
Name: SKiLLa
Date: 12/23/2003 3:35:21 AM
Comment:
> acid@stardust-studios.net.com.co.uk.au.us.museum.info.org Above is a syntax-wise a valid email address, somebody could have the domain info.org and create a lot of subdomains ... The only thing I miss is a check for the domainname part (without extension) to be equal or greater than 2 and smaller than 64 ...


Title: IPs & Multiple TLDs
Name: Acid
Date: 12/15/2003 5:37:05 AM
Comment:
Nice expression, however would be much better if it supported IP address within the square brackets as it doesn't seem to allow this. The only other problem i can see with it is like several other expressions it allows excessive consecutive TLDs to be entered at the end of the address, for example the address: acid@stardust-studios.net.com.co.uk.au.us.museum.info.org Is accepted by the expression as a valid email address, when obviously it isn't, although it is unlikely that anyone would enter an email address with all those TLDs, IMO it is best to heavy the expression air tight, or as close to it as possible, you may want to add some additionsl code to prevent consecutive TLDs which are obiovusly bogus, like .net.com.us for example.


Title: Fixed
Name: Gavin Sharp
Date: 9/24/2003 10:51:58 AM
Comment:
I've made it compatible with the .museum TLD.


Title: TLD museum
Name: Remi Sabourin
Date: 9/24/2003 1:24:03 AM
Comment:
Museum is a TLD (6 characters)


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