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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Email Validator
Expression
^([a-zA-Z0-9]+(?:[.-]?[a-zA-Z0-9]+)*@[a-zA-Z0-9]+(?:[.-]?[a-zA-Z0-9]+)*\.[a-zA-Z]{2,7})$
Description
After reading RFC2822 (then taking two asprin) I've come to the conclusion that I will not allow all RFC compliant email addresses to be entered in the forms on my website and will never have an issue with it. I demand a stricter tolerance for my website than RFC allows. If you're like me and only want to allow 99% of those email addresses entered into web-forms then use this little gem of an email checking regex. Also, I've never met anyone who would submit an email address taking full advantage of RFC2822's allowances nor would I care to accommodate one who would.
Matches
name@email.com
Non-Matches
_name@.email.com
Author Rating: The rating for this expression. Ted Cambron
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: Updated Again
Name: Ted Cambron
Date: 9/20/2014 10:08:24 PM
Comment:
I love my little email verification regular expression. It's so simple yet so effective.


Title: re ...
Name: random832
Date: 3/5/2009 9:49:42 PM
Comment:
Actually an email username ending in "..." is NOT a valid email address - two dots adjacent to each other is not allowed by the standard. Re the "full 822 regex" - Why does that regex target the 'address' syntax element when 'addr-spec' would be more appropriate for this purpose?


Title: Another Critic
Name: Ted Cambron
Date: 6/18/2008 12:22:45 AM
Comment:
Wolfgang, this regex isn't perfect but for you to post about what you think is not a valid email address is your business. If you don't want to accept an email address with an username that has "..." at the end that's fine and dandy but don't think that what you feel is not correct is a "malfunction" on anybody elses behalf. Quite honestly, I don't like it either but that's the way it is and RFC allows even more than that.


Title: Re: Malfunction
Name: h
Date: 5/16/2008 12:45:26 PM
Comment:
That is a valid e-mail address - it maybe is not _your_ e-mail address, but what if I had an e-mail address with "..." at the end of the username?


Title: Malfunction
Name: WolfgangBadura@aon.at
Date: 4/18/2008 4:30:50 PM
Comment:
The pattern allows the address "WolfgangBadura...@aon.at". This is a malfunction. My pattern is "[a-z0-9]+[a-z0-9_%-]*((\.[a-z0-9_%-]+)|([a-z0-9_%-]+)*)@[a-z0-9-]+\.[a-z]{2,4}\b". Then the upper address causes an error!


Title: um...
Name: random832@gmail.com
Date: 4/16/2008 12:25:16 PM
Comment:
"I re-enabled this regex, with a little user suggested edit, because I demand a stricter tolerance for my website than RFC allows. If you're like me and only want to allow minimal characters, then use this regex. Also, I've never met anyone who would submit an email address taking full advantage of RFC2822's allowances nor would I care to accomodate one who would." What if someone's _actual e-mail address that they really want to use_ fails your validation? By claiming that you've never met anyone who would and implicitly that you "don't care to" accomodate them, you're just _assuming_ that anyone whose e-mail is valid but doesn't pass your regex is just trying to be difficult. Your regex doesn't even allow people to put in username+something@gmail.com which gmail does to automatically file things into labels. That's hardly an attempt to get the weirdest e-mail address possible while still being technically valid. Hell, by limiting top-level-domains to 2-4 letters, you're excluding .museum - do you REALLY want to exclude people who work for museums? Do you think they're choosing that TLD for their email address to make some kind of point?


Title: A Formal Appology
Name: Ted Cambron
Date: 8/7/2007 7:51:24 PM
Comment:
I appologize for my ignorance. Randal is here! The master has spoken and I will remove this regex (if I can) after making sure this appology is noted. Randal Schwartz is the authority and everyone should listen with great intensity. My actions are inexcusable and I sit beside myself wondering what else to do to make it right.


Title: Did you not read IETF RFC2822?
Name: STrRedWolf
Date: 8/7/2007 7:14:19 PM
Comment:
I'm sorry, but Randall's right here. First, read RFC2822 from ietf.org, which is the updated version of RFC 822, aka "How Email Messages and Addresses are Built." Then read RFC 3696. Or, if you're thinking "tl;dr" then pull this Linux Journal article on validation in PHP: http://www.linuxjournal.com/article/9585


Title: No longer trying to teach the pig to sing
Name: Randal L. Schwartz
Date: 8/7/2007 5:34:15 PM
Comment:
After the private email you've been sending me, it's clear that even when you accept that I've been posting here, you just don't get it about why I'm trying to correct your damn broken regex. And yes, this *is* the regex library, and this *is* why I'm trying to fix it. People will see this, and get harmed by it, and it's your fault. I'm just trying to minimize the damage. So much for trying to teach the pig to sing (it'll never work, and it annoys the pig). As for triage, you're now in the "dead" category, instead of the "could save" category. What a waste of my time, except perhaps for the onlookers who now are pretty clear that your regex is broken.


Title: Randal is merlyn
Name: Ted Cambron
Date: 8/7/2007 4:40:49 PM
Comment:
Randal's page is http://www.stonehenge.com/merlyn/ The methods used by you here are that of ignorance. No one can take you seriously when you make statements like, and I quote "...then you're not worth wrassling with any longer. Some would say you passed that point a few posts back, but I'm really trying to be helpful here." I looked a few posts back and can't find anything out of line that I posted contrary to your immature and unprofessional postings. No one appears to be "wrassling" here no matter how much you provolk it. Then to sum it up and say you trying to help?! Let me remind you that this is the Regex Library. I don't think you realize that.


Title: Proof
Name: Randal L. Schwartz
Date: 8/7/2007 10:18:17 AM
Comment:
I can't believe you have this difficulty (a) accepting that regardless of who I am, the point is valid, and you should change your behavior, and (b) that it's really me, and (c) I *might*, just *might* have differing writing styles when I write columns vs when I'm correcting BROKEN POSTINGS in a BLOG. Tell you what. I lifted the text of your last post, and put it at http://www.stonehenge.com/pic/what-an-idiot.txt - go verify it there (I use /pic/ because it's not part of my change control system like the rest of the site). If that's not proof for you, then you're not worth wrassling with any longer. Some would say you passed that point a few posts back, but I'm really trying to be helpful here.


Title: Will the real Randal please stand up?
Name: Ted Cambron
Date: 8/6/2007 4:33:45 PM
Comment:
I'm glad a link was posted to the real person's work. Now everyone interested can read what the real Randal has to say. I would like to give a quote from the real man to show the contrasting behaviour patterns. Randal: "Look at the CPAN first, learn to read every part of a regular expression, and ask around to see if your solution makes sense. Until next time, enjoy!" Compare this to what the Randal wanna-be posted here and I'm sure you'll see the difference.


Title: Hi Randal!
Name: Larry Wall
Date: 8/6/2007 4:20:06 PM
Comment:
I knew Randal Schartz. Randal Schwartz was a freind of mine. You, are no Randal Schwartz!


Title: It's really me. I'm consistent on this
Name: Randal L. Schwartz
Date: 8/6/2007 9:30:32 AM
Comment:
see my column http://www.stonehenge.com/merlyn/UnixReview/col60.html, starting where I say "I don't think more than a few weeks goes by before I see someone attempt to match ...". I'm very consistent on this issue. You, sir, are being unteachable, which is why I'm continuing to raise my voice. I'm sick and tired of people rejecting valid email addresses in web forms. If I can possibly make a difference, I will. This is an important issue to me.


Title: Randal?
Name: Ted Cambron
Date: 8/6/2007 8:43:41 AM
Comment:
Mr. Schwartz, I have read all your articles at Stonehenge and enjoyed them very much yet reading your posts here are of a different nature. A simple writing analyst tells me that your either not Randal Schwartz or bi-polar and lacking medication. In either case please see a doctor.


Title: still wrong. there's no need for false positives or false negatives
Name: Randal L. Schwartz
Date: 8/6/2007 2:57:20 AM
Comment:
"If you had 10 million e-mail addresses to test, would you test every one of them again a 10,000-character regex string?" Yes I would if I wanted correct results. Why is that so hard for you to understand? And that author is saying that yes, regex is nearly the wrong solution for this. Why do people insist on validating a date or an IP address with a regex? I DON'T KNOW. MAYBE THEY ARE IDIOTS. Regex are NOT a universal solution. To pretend they do everything is to pick up a hammer to whack in a screw. Wrong tool for the job. Email validation, date validation, ip address matching - ALL WRONG FOR REGEX. Sheesh.


Title: Forgot to mention...
Name: Speednet
Date: 8/3/2007 2:41:58 PM
Comment:
One more thing. In that link to the "correct" e-mail pattern, it includes the sentence: "The grammar described in RFC 822 is suprisingly complex. Implementing validation with regular expressions somewhat pushes the limits of what it is sensible to do with regular expressions..." So even the author of that document seems to imply that it should not be used in all (or even most) cases.


Title: Have you flipped your lid?
Name: Speednet
Date: 8/3/2007 2:37:54 PM
Comment:
Randal, the regex pattern described in the link you provided is wonderfully long, but way too complex for simple e-mail tests. Your argument is like saying if your web site doesn't work with every single web browser ever made, including Netscape 2.0, then it's WRONG, WRONG, WRONG. The is nothing WRONG about a simple e-mail validator. What if it's being used as a first-pass filter? If you had 10 million e-mail addresses to test, would you test every one of them again a 10,000-character regex string? Your comments are close-minded, and, dare I say it? Wrong.


Title: Huh?
Name: Randal L. Schwartz
Date: 7/30/2007 4:19:36 PM
Comment:
"Randal Schwartz is an idol of mine and I don't appreciate the closed minded comment that's not his style." What does that mean? It's always been my style to tell the truth. The *minimum* regex to parse legal RFC822 addresses is given in http://ex-parrot.com/~pdw/Mail-RFC822-Address.html. ANYTHING SHORTER IS WRONG. And everything posted HERE has been SHORTER than that. So EVERYTHING HERE IS WRONG. How hard is that to comprehend?


Title: Thank you
Name: Ted Cambron
Date: 7/29/2007 1:37:38 PM
Comment:
Thank you Speednet! This is great feedback. I will update and test when I get some time. Randal Schwartz is an idol of mine and I don't appreciate the closed minded comment that's not his style.


Title: WRONG WRONG WRONG
Name: Randal L. Schwartz
Date: 7/28/2007 9:17:44 PM
Comment:
This fails to validate *actual* *working* email addresses that I'm aware of. It's broken. DO NOT USE THIS REGEX. See RFC822 and the Email::Valid module in the Perl CPAN. PLEASE STOP POSTING BROKEN EMAIL VALIDATORS TO THIS RESOURCE.


Title: Maybe a little too simple?
Name: Speednet
Date: 7/28/2007 6:26:36 PM
Comment:
The pattern will allow the address ".@something.com" and other addresses containing no alpha/numeric characters. Maybe if you extended it just a bit you could make it more solid while retaining its simplicity: ^([a-zA-Z0-9]+[a-zA-Z0-9._%-]*@(?:[a-zA-Z0-9-]+\.)+[a-zA-Z]{2,4})$ Performance is increased by greedily capturing as many alpha/numeric characters as possible in the first expression. You can actually make it perform even better by replacing "[a-zA-Z0-9]+" with "\w+", the only side-effect being that the e-mail address could potentially start with an underscore ("_"). (Is that in the spec?)


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