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_\-])+)*@((\[(((([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])+)*))$
Description
Email expression match that allows both IP addresses and regular domains. In the case of an IP address it makes sure that it is no more than 255 for each part. Thanks to Ivan R. and Michele for some bug fixes...BTW: This is my second reg expression ever so be nice :-D
Matches
[email protected] | john.doe@[255.008.09.090] | [email protected]
Non-Matches
Author Rating: Not yet rated. Myle Ott
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: Email address formats are evil!
Name: Robert db
Date: 11/27/2005 4:13:01 AM
Comment:
Here's a perfectly valid email address ... [email protected] Paraphrasing the rfc, the localpart of the address must be a "word" followed by zero or more words each of which may be preceded by a dot. A word can be an "atom" or a quoted string. An atom can contain any ascii character except controls, whitespace and characters from this list "(", ")", "<", ">", "@", ",", ";", ":", "\", <">, ".", "[", "]" With a quoted string you can put ANYTHING between the quotes! Strictly speaking the address jürgen.mü[email protected] is illegal because it uses non-ascii characters. It's also slightly unsafe because it assumes the latin1 character set. However, "jürgen müller"@web.de is legal. I think I'll stop there, I wouldn't want to get too technical. :-) Or evil... robert"@"[email protected]


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


Title: Ouch...
Name: FreeBee
Date: 7/5/2005 10:03:27 AM
Comment:
We all make mistakes once in a while, and clearly I'm not perfect either :) The "([0-1]\d\d|2[0-4]\d|25[0-5])" in my former post should actually be "([0-1]?\d?\d|2[0-4]\d|25[0-5])" to allow for the omission of leading zeros, like your own regexp does. The final expression then looks like "^(\w|[-])+(\.(\w|[-])+)*@((\[([0-1]?\d?\d|2[0-4]\d|25[0-5] )\.([0-1]?\d?\d|2[0-4]\d|25[0-5])\.([0-1]?\d?\d|2[0-4]\d|25[0-5])\.([0-1]?\d?\d|2[0-4]\d|25[0-5])\])|((([a -zA-Z0-9])+(([-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([-])+([a-zA-Z0-9])+)*))$" Sorry for the mix-up. :)


Title: One suggestion...
Name: FreeBee
Date: 7/4/2005 8:58:30 PM
Comment:
I must admit, it's a great job you did there, Myle. Ok, some people are right saying that it still allows for some erroneous addresses, but it might be hard to cut those out. However, there is something else you could do. Replace every occurence of "[a-zA-A0-9_\-]" with "\w|[-]", and "(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))" with "([0-1]\d\d|2[0-4]\d|25[0-5])". That makes the whole expression look like: "^(\w|[-])+(\.(\w|[-])+)*@((\[([0-1]\d\d|2[0-4]\d|25[0-5])\.([0-1]\d\d|2[0-4]\d|25[0-5])\.([0-1]\d\d|2[0-4]\d|25[0-5])\.([0-1]\d\d|2[0-4]\d|25[0-5])\])|((([a-zA-Z0-9])+(([-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([-])+([a-zA-Z0-9])+)*))$" It still does exactly the same, but the length drops from 349 to 231, which is a 128 bytes gain. That makes it a bit easier to read as well.


Title: Error
Name: David van Leerdam
Date: 9/10/2004 7:11:34 AM
Comment:
It says '[email protected]' is valid though it is definitely not.


Title: Multiple TLD Bug
Name: Acid
Date: 12/15/2003 5:19:25 AM
Comment:
I've come across another bug with this expression, this code seems to match email address that have excessive multiple TLDs at the end of the address, for example the following address is obviously not valid, but will be accepted by this expression: [email protected] Although in the case of some TLDs that are double-barreled, such as co.uk, multiple TLDs do need to be enabled, however you might want to add a little extra to this code to perhaps limit the number of TLDs that can be entered, or perhaps when this code is integrated into a site/program include a few if statements for further validation of the addresses.


Title: A valid emailadress that does not match
Name: patrick
Date: 12/10/2003 10:38:23 AM
Comment:
The following adres is a valid one but does not match according to your validator [email protected] kind regards


Title: One Character TLDs
Name: Charlie
Date: 10/30/2003 4:29:57 PM
Comment:
However, I'm fairly certain that 1 character TLDs will NEVER be in existance (isn't it against the rules?). Therefore, your Regex should not allow a single character TLD.


Title: Problem?
Name: Myle Arif Ott
Date: 5/21/2003 7:56:17 PM
Comment:
I don't really consider that a problem as I wanted this regex to allow for new TLD's that have not yet come into existance. As I don't have the time to check for every new TLD (and update my regex) and since I would rather let a couple phony emails through rather than block a legit one, I did this intentionally. Thankz for your help though :-D


Title: Problem
Name: Peter P
Date: 5/21/2003 9:05:01 AM
Comment:
This matches on: [email protected] which is not a valid address


Title: Hmmm...
Name: Myle Arif Ott
Date: 4/23/2003 12:03:05 AM
Comment:
I read your comments, thank you. I have fixed the regex to make sure that the domain does not start or end with a - (which I now realized is not allowed). The new one can be found at the top of the page (I replaced the old one).<BR><BR>PS: What is this IgnoreCase you speak of? I'm not familiar with it as this is my first regex. I couldn't find it...


Title: Middenheid
Name: Chris Mulvey
Date: 4/22/2003 9:07:48 AM
Comment:
I think this suits better: "^([a-z0-9_\-])+(\.([a-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-z0-9\-])+\.)+([a-z]{2}\.[a-z]{2}|[a-z]{3})))$" allows for top-level domain qualifier also (.com, .co.uk, .net, .ac.it, etc) yours validates [email protected] [email protected] also, not keen on [email protected] or [email protected] which although 'valid' should be discouraged...also, do email address not need to start with at least one alpha char? [a-z][rest of your regexp] PS: Have taken out upper case A-Z and used IgnoreCase property instead, just for simplicity...


Title: Please Note
Name: Myle Arif Ott
Date: 4/17/2003 12:26:45 AM
Comment:
For required [] brackets in IP's please use the one at the top of the page (to the left of rating and right below REGULAR EXPRESSION DETAILS)


Title: Fixed It
Name: Myle Arif
Date: 4/16/2003 3:10:20 PM
Comment:
Fixed a few other bugs as well...<BR><BR><B>Use this for optional [] brackets in IP's</B>: ^([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-Z\-])+))$<BR><BR><B>Use this to disallow [] brackets in IP's</B>: ^([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-Z\-])+))$


Title: IP addresses not correct format
Name: Noah
Date: 4/16/2003 12:37:32 AM
Comment:
According to the RFC, mail addresses for IP Literals should be in this form (note square brackets): john.doe@[255.008.09.090] not this form: [email protected] This is called a Domain Literal email address. See RFC 1123 Section 5.2.17.


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