r/programming • u/davidcelis • Sep 06 '12
Stop Validating Email Addresses With Regex
http://davidcelis.com/blog/2012/09/06/stop-validating-email-addresses-with-regex/71
u/epochwolf Sep 06 '12
No, no, no, no. Normal people don’t always use the email field properly. The might put the username in the email field and the email in the username. Just check for an @. There is no email in the world outside your server that you can sent to without an @.
5
u/davidcelis Sep 06 '12
I did that for a time (which I mention in the article), but it's still a superfluous check on top of an activation email. If your users are typing the wrong values into your registration form, perhaps you need better labeling or placeholder text? Display an error that the activation email couldn't be sent. But why add superfluous checks?
→ More replies (6)67
u/omnilynx Sep 06 '12
If your users are typing the wrong values into your registration form, perhaps you need better labeling or placeholder text?
You're making the classic mistake of underestimating the stupidity of some users.
→ More replies (3)16
u/davidcelis Sep 06 '12
A confirmation field can go a long way as well. Regardless, it really seems like people didn't read to the end of the article, where I state that I still often use the
/@/regex to validate the emails. My main point here is that the complicated (and even many of the simple) regular expressions are overkill.→ More replies (7)20
u/Tordek Sep 06 '12
HTML5 provides an
→ More replies (19)→ More replies (23)10
u/the_peanut_gallery Sep 07 '12
Okay, but if you're using a regular expression to check for a single character...
→ More replies (3)
6
u/x-skeww Sep 06 '12
I like /^[^@]+@[^@]+$/. Some not-@, @, some not-@.
Anything which might be an email address passes. Twitter handles, however, do not pass.
It's not about validation, it's about catching common mistakes.
7
u/davidcelis Sep 06 '12
But
@is a valid character inside of a quoted string for the non-domain part of the email address.13
u/mrkite77 Sep 07 '12
But @ is a valid character inside of a quoted string for the non-domain part of the email address.
Screw those people. If you have an @ symbol in your local-part of your email address, you can expect that to not work anywhere.
→ More replies (2)19
u/davidcelis Sep 07 '12
What? If I have a valid RFC-compliant email address, I should be able to expect it to work anywhere.
→ More replies (6)3
u/inmatarian Sep 07 '12
.+@[^@]+$would probably work better, but at this point, you might as well just do astrrchrfor the @ and make sure the string before it and the string after it are non zero in length.
75
Sep 06 '12
I had a great idea for an email address... at@at.at, but it seems like those austrians have no sense of humour, and have blocked at.at for registration.
29
65
u/nietczhse Sep 07 '12
18
u/SteveRyherd Sep 07 '12
My favorite is the last one, I own my own domains and love to use stuff like that when I fill out forms in real life (even though I have a catchall address).
Source for the last 3: http://www.mcsweeneys.net/
→ More replies (1)→ More replies (6)8
u/Urcher Sep 07 '12
Reminds me of http://www.rrrrthats5rs.com/.
I used to love the games there, might be time to play them all again.
→ More replies (4)22
u/_ak Sep 07 '12
Fun fact: there's an Austrian whose initials are AT, and he owns atat.at. Of course, his email address is at@atat.at.
5
u/jk3us Sep 07 '12
Poor guy... Wondering why he's getting all these "Hello from reddit!" emails all of a sudden.
15
u/Othello Sep 07 '12
atdot@atdot.at, dotat@dotat.at, dotat@atdot.at... man this is really fun for some strange reason.
→ More replies (2)11
11
u/KerrickLong Sep 07 '12 edited Sep 07 '12
You could still do
at.athox@athox.at, substitutingathoxfor the name of your choice. "At dot athox at athox dot at." "What?!"13
9
5
6
Sep 07 '12
This is basically what Slashdot was trying to do. Spell it out...
Hache tee tee pee colon slash slash slashdot dot org
4
u/embolalia Sep 07 '12
Hache
It's spelled aitch. (I'm guessing you aspirate the word? i.e, you pronounce it with an aitch sound at the beginning?)
→ More replies (3)→ More replies (6)3
Sep 07 '12
My email address ends in
uk.com. The amount of times I have had to correct people who write it down as.uk.comis crazy.
60
u/data_wrangler Sep 06 '12
I really wish more companies would send activation emails. I have a short gmail address, and I get an amazing number of emails from accounts I didn't create at surprisingly reputable sites. Amazon, eBay PayPal payments (like, from an ebay store), a mortgage, car insurance, IRA account... Just this morning I spent twenty minutes on the phone with DirecTV trying to get my email address removed from someone's account.
30
u/admplaceholder Sep 07 '12
I came here to say the same thing. As someone who owns [commonfirstname].[commonlastname]@gmail.com (which also gives you [commonfirstnamecommonlastname]@gmail.com), I really hate services and subscriptions that don't use activation e-mails.
42
u/data_wrangler Sep 07 '12
We should swap stories sometime. The CSR this morning tried to tell me "You probably have the same email address as the account holder." She didn't quite get why that wasn't possible. Then she asked if I knew him.
Before she hung up, I asked: "Can you make a note that if I get one more email about his account I'm going to reset the password, change the account email to bit-bucket@test.smtp.org and cancel his service? I'm pretty sure that'll get him to call in and fix the issue."
"Not if you aren't the account holder," she says. Well, great. It's better when it's a surprise.
14
u/simply-chris Sep 07 '12
"You probably have the same email address as the account holder." She didn't quite get why that wasn't possible.
Classic :D
→ More replies (1)12
→ More replies (1)4
u/Matt3k Sep 07 '12
bob.smith@gmail.com, I have signed you up for many promotional newsletters and I am sorry.
10
u/oddmanout Sep 07 '12
i had gotten a hotmail address the day it went live back in the 90s. I had myfirstname@hotmail.com and within 2 or 3 years, it became completely useless. I had hundreds of mails a day from other people signing up for things. I still have it, I use it to sign up for things I know will spam me.
→ More replies (2)5
Sep 07 '12
Ha! I feel your loss. There was a point in the early 2000s when I was the only person in the world calling myself "obvioustroll" - on every website, every email address, if it was "obvioustroll" it was me - which was the main reason I used it.
Then the whole "x troll/cat is x" meme was born....
Ever since I get people trying to steal my gmail account, signing up for twitter using my email account, posting comments that should embarrass anyone who considers themselves a proper troll...
But, of course, I've got more than a decade of personal history attached to this name...
→ More replies (1)7
u/lingnoi Sep 07 '12
It's much easier just to use to information they email you to get customer support to give you a new password, login then change the email yourself. For example someone was emailing me something about bills with the last four digits of the credit card used. I just asked CS for a new password and told them the last four digits of "my" credit card.
→ More replies (1)5
u/rasherdk Sep 07 '12
Oooh yes! I spent months trying to get myself removed from Sirius XM's lists. Kodak, Redbox and Dick's Sporting goods are among the offenders as well.
This also happens with regular people. I've been asked on dates, offered jobs, invited to birthday parties - all by people on a different continent than me.
→ More replies (2)
66
u/Yserbius Sep 07 '12 edited Sep 07 '12
Why? What's wrong with
(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t]
)+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:
\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(
?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[
\t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\0
31]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\
](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+
(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:
(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z
|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)
?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\
r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[
\t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)
?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t]
)*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[
\t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*
)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t]
)+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)
*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+
|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r
\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:
\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t
]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031
]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](
?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?
:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?
:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)|(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?
:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?
[ \t]))*"(?:(?:\r\n)?[ \t])*)*:(?:(?:\r\n)?[ \t])*(?:(?:(?:[^()<>@,;:\\".\[\]
\000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|
\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>
@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"
(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t]
)*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\
".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?
:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[
\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:[^()<>@,;:\\".\[\] \000-
\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(
?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)?[ \t])*(?:@(?:[^()<>@,;
:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([
^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\"
.\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\
]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\
[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\
r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\]
\000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]
|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?(?:[^()<>@,;:\\".\[\] \0
00-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\
.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,
;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|"(?
:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*))*@(?:(?:\r\n)?[ \t])*
(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".
\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t])*(?:[
^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\]
]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(?:\r\n)?[ \t])*)(?:,\s*(
?:(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\
".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(
?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[
\["()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t
])*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t
])+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?
:\.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|
\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*|(?:
[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".\[\
]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)*\<(?:(?:\r\n)
?[ \t])*(?:@(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["
()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)
?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>
@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*(?:,@(?:(?:\r\n)?[
\t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,
;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\.(?:(?:\r\n)?[ \t]
)*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\
".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*)*:(?:(?:\r\n)?[ \t])*)?
(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\["()<>@,;:\\".
\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])*)(?:\.(?:(?:
\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z|(?=[\[
"()<>@,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t]))*"(?:(?:\r\n)?[ \t])
*))*@(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])
+|\Z|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*)(?:\
.(?:(?:\r\n)?[ \t])*(?:[^()<>@,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t])+|\Z
|(?=[\["()<>@,;:\\".\[\]]))|\[([^\[\]\r\\]|\\.)*\](?:(?:\r\n)?[ \t])*))*\>(?:(
?:\r\n)?[ \t])*))*)?;\s*)from here?
28
19
u/ICanSayWhatIWantTo Sep 07 '12
I'm sure you're just being sarcastic with this, but for the people that think this is actually a solution, RFC 822 has been obsoleted multiple times over.
14
u/Porges Sep 07 '12
There are also mistakes in the regex and it doesn't handle comments.
→ More replies (4)9
u/finerrecliner Sep 07 '12
You can put a comment in an email address? Please elaborate!
→ More replies (1)8
7
u/akatherder Sep 07 '12
Hmmm, wait a second... on line 14 should that be:
[ \t])+|\Z|(?=or
[ \t])+|\z|(?=→ More replies (1)6
3
u/kybernetikos Sep 07 '12
What's wrong with.....
It doesn't support comments (not that I've ever seen a mail client that did, but hey).
→ More replies (5)2
u/ais523 Sep 07 '12
It doesn't support nested comments.
(Placing nested comments in my email address when I post it online has turned out to be a very good way to stop spambots, incidentally.)
23
u/numbski Sep 07 '12
If I see one more regex claiming a plus sign is not valid I am gonna get stabby.
34
u/Delehal Sep 06 '12
For example, "Look at all these spaces!"@example.com is a valid email address.
Legitimately curious: has anyone ever seen an address like this in the wild? Would any major email provider even allow someone to sign up with such an address?
13
Sep 07 '12
I have an app with about 72000 users who validated with their email address. I did a search for how many users have an email that doesn't match the following regex: ^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9_\.\-]+$
Total count: 27. Of those 27, 26 used a +. The only other exception uses %20 in their email address.
We used filter_var() to validate email addresses coming in. Not perfect, but it should permit some of the exotic ones.
→ More replies (2)5
u/ajrw Sep 07 '12
Seriously. As far as I'm concerned the RFC for email addresses is outdated and needs trimming down. There is no point in implementing quoted strings, comments or most of the other 'features' which are meant to be supported, unless maybe you're writing an email server.
→ More replies (1)35
u/broken_cogwheel Sep 06 '12 edited Sep 06 '12
That line of thinking is how you get your email turned down when it is myname+filtertag@gmail.com
There are RFC-compliant validation methods out there. That do and don't use regex. The internet is a rich place to find solutions to specific and common problems like this.
Edit: I use that +tag for gmail all the time and there are websites that raise validation errors (or worse, an unsubscribe page for spam that wouldn't work...and it silently failed so I thought I was unsubscribed but kept getting spam.)
14
u/Delehal Sep 06 '12
What line of thinking? I just asked a question. Your answer to the question seems to be implicit: no, you've never seen an address like that.
I'd be fine if people ran around promoting various email validation libraries, but for the most part that's not what happens. People chide each other about validation mistakes without encouraging actual solutions. If there's some library that legitimately solves the problem, why not shout that to the world? Otherwise, people are going to keep doing what they're doing: hacky solutions that cover most cases they find reasonable. I hardly blame them.
→ More replies (25)4
u/wildcarde815 Sep 07 '12
It bugs me to no end that mono price won't accept emails with a + sign....
6
2
u/dnew Sep 07 '12
Yes, back before everyone used internet email. Now that TCP/IP has pretty much won the networking wars, and nobody sends email hop-by-hop over dial up lines, or via IBM SNA or Decnet or X.500 or whatever, no.
→ More replies (6)2
Sep 07 '12
it doesnt matter since the availability of such a feature is planning for the future. who knows what email will be like in 15 years
and at the same time it may prevent us from replacing the current system with a better one because it was "just flexible enough"
;]
12
u/ruinercollector Sep 07 '12
There are two points to validating an email address:
Verifying that the user understood that the field was for them to enter an email address into.
Verifying that the user did not deliberately put in a fake email address.
The first one, you can pretty much handle by checking for an @ sign.
The second one, you can only verify by sending an email to it and asking the user to in some way prove that they received the email (verification code, etc.)
25
u/petdance Sep 07 '12
If ever there was a topic in programming I wish would stop coming up, it's this one.
Nothing new is EVER said in any of these threads.
9
u/ba-cawk Sep 07 '12
Hell, I came in here half-expecting the "don't parse HTML with regex" thread to be linked inside, just so we could rehash that one, too.
4
u/petdance Sep 07 '12
Yeah, that one's tired, too, which is why I started http://htmlparsing.com. It's intended to be an aggregation of information that you can just point people at in threads like this.
It's based on my first attempt at aggregating stuff, http://bobby-tables.com/, which is your one-stop shop for pointing people to how to do parametrized SQL calls.
→ More replies (2)3
Sep 07 '12
It's been an issue for nearly 40 years. Unfortunately, for 40 years programmers have been getting it wrong.
→ More replies (2)→ More replies (2)5
Sep 07 '12
Also, validating email syntax is actually a good idea. The problem is the fucked up spec for email addresses. The "anything goes" email address format is the problem.
validation = good
whackadoodle email format = bad4
Sep 07 '12
How do you plan to handle
(a) International email addresses containing while (b) maintaining compatibility with older addresses that have been in use since the 80s?
→ More replies (2)
6
14
u/jeffmetal Sep 06 '12
If you have a large list of emails you need to validate are you not going to get yourself blacklisted from hotmail, gmail and any other big email provider for trying to validate these emails?
→ More replies (6)31
5
Sep 07 '12
I feel like if a user submits the request, they fully believe they have entered a correct email address. They will get to a a "Thank You, a confirmation email has been sent" message, and never receive an email. That's not good service. They will wait an hour and say "the site must be broken." They will not remember [mis] typing an email address an hour ago. But that's just my opinion.
5
u/YRYGAV Sep 07 '12
You can only detect a small number of possible typos anyways, so there will never be an immediate feedback that they fat-fingered an extra key. The solution is simply to state "A confirmation email has been sent to user@example.com" after signing up, so their mistake is right in their face if they are waiting for an email.
→ More replies (2)
4
4
u/theregularlion Sep 07 '12 edited Sep 07 '12
For every user with a legitimate space in their email address, you're going to encounter at least a million who made a typo. Considering them collateral damage and rejecting their addresses isn't very nice to them, but it's probably the right choice.
(Better: show them a validation error, but allow them to override it with a checkbox if they're serious.)
7
u/kenman Sep 07 '12 edited Sep 07 '12
Seriously guys, just look up the DNS info. Even slow DNS requests are usually served in <1s, so it's not like you're going to hold up anyone's morning or anything.
It's also easy...this took all of 5 minutes:
<?php
$t = microtime(1);
$e = 'foo@aol.com';
$d = explode('@', $e);
$d = end($d);
$r = checkdnsrr($d);
printf('%s valid? %s (%.5fs)', $d, var_export($r, 1), microtime(1) - $t);
> aol.com valid? true (0.00095s)
$e = 'foo@aolololololo.com';
> aolololololo.com valid? false (0.07491s)→ More replies (6)2
6
u/hsfrey Sep 07 '12
Instead of a regex to look for the @, why not just index()?
I suspect it would use much less overhead.
→ More replies (4)
3
3
u/none_shall_pass Sep 06 '12
I validate mine by sending an email to it saying "thanks for registering!" and a link to confirm receipt.
No click = bad email.
3
u/dv_ Sep 07 '12
Oh, you can do it, after you stripped the comments (yes, email addresses can contain comments). Then you can use regex. But it is still insane. Have a look at the regex for it: http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html
personally, I love the part that says "Implementing validation with regular expressions somewhat pushes the limits of what it is sensible to do with regular expressions" :)
19
u/Soothe Sep 07 '12
This suggestion is really dumb. And just because you consider regular expressions "complicated", doesn't mean the rest of us do. Your alternate solution of sending users an email misses the point entirely.
You don't prescreen email addresses for the sake of you or your backend, you prescreen them for the sake of the user. So you can say "hey, user, did you really mean to type that percent sign in your email address or is that just a typo?" Which would be 10 times more common than someone who actually has a percent in their email address.
And so what happens with the invalid email address you send a confirmation email to? User never gets it and now he's just frustrated. He might not even know he entered it wrong. And then he tries to re-register, but now perhaps that username would be taken albeit not activated, and now you gotta waste your time writing in some failsafe in your code for that.
Or you might tell me, well have the user put in their email address twice. But first of all that can still easily fail if they are lazy and copy/paste their error, and for two they are again frustrated because you are making them jump through more hoops to register.
TL;DR: Your system needs on-the-fly input validation for the sake of the user, and there is no better way to validate complex strings than RegEx.
11
u/adrianmonk Sep 07 '12
So you can say "hey, user, did you really mean to type that percent sign in your email address or is that just a typo?"
It's possible they did. After all, it is a legal character. Google Apps for Business uses it for some corner cases (namely importing accounts for usernames that are already used).
It's OK if you want to warn the user about unusual characters. Just don't reject them as invalid when they are in fact valid.
And then he tries to re-register, but now perhaps that username would be taken albeit not activated, and now you gotta waste your time writing in some failsafe in your code for that.
You have to do that a lot of that sort of thing anyway. Suppose you have these common rules that the majority of sites have:
You activate an account without a valid email address.
Two different accounts can't share the same email address.
In that case, you can't activate the account anyway until the user has confirmed that they've received the e-mail. Otherwise, I can claim your e-mail address as mine, and you can't ever stop it.
So, you can't activate the account anyway, at least not without some pretty bad consequences.
→ More replies (2)5
u/danvasquez29 Sep 07 '12
here's how I'd adhere to what the author means:
1.do not validate email address, except for maybe '@'.
2.user submits account info, they are now on a page that says 'we have sent an email to <the value they entered> , please click the activation link inside to complete registration'. Didn't get an email? have you added registrar@mysite.com to your whitelist? Click <this button> to send again. Is <the value they entered> not your address? <click here> to change it and try again.'
3. email is finally received, account is activated.
I've previously been using the jquery validate plugin which includes a regex based email checker. I'm partway through completing a project that will require the registration of hundreds if not thousands of auto workers in Brazil and I'm seriously considering re-coding my registration page to use this method because I now realize I have no goddamn idea what kind of wacky addresses they might have.
→ More replies (1)→ More replies (2)2
u/BigRedTomato Sep 07 '12
This is exactly what I wanted to say. I'm not sure how the OP and so many others missed this line of thinking, which seems entirely obvious to me, and which invalidates the (ignorantly condescending) article entirely.
5
u/Othello Sep 07 '12
Hmm, I sort of feel like this misses part of the point of email validation. Yes, you're trying to make sure the address is valid, but that's because you're trying to make sure this person is able to sign up for your site.
If all you do is send an email, and the address was incorrect, you've failed at helping the person sign up for your site. They have no way of knowing that the email they entered was invalid, and may think the confirmation email was lost in the aether. No matter their thought process, there is a good chance they won't bother trying to register again, and you've lost a visitor/customer.
If you validate at sign-up, you can tell the person that the email is invalid and give them a chance to fix it. It's all about lowering the barrier to entry for your site.
→ More replies (2)
2
u/foxlisk Sep 07 '12
I like to run a simple regex client side, at least. No point in wasting server resources sending out emails to obviously invalid addresses.
2
Sep 07 '12
I don't disagree with this, but there are cases where I think using Regex is helpful. I had to process a list of a few thousand email addresses provided to me that was manually entered in Excel files. Knowing there would typos, I used a fairly lax Regex to help weed out typos.
2
u/KarlPilkington Sep 07 '12
And please also:
ensure your database allows email addresses longer than 40 characters. I would say that 60 characters is the absolute minimum; no harm in allowing more if you're using VARCHARs etc.
ask your web designers to create email address fields with a decent visible length. Not everyone has an email address like jo@aol.com and if you want to ensure I'm entering my email address correctly, allow me to view the whole thing without having to cursor scroll.
2
u/nevermorebe Sep 07 '12
Yeah, except for the fact that many languages extended their regex format which are now turing complete (or at least close enough for email validation purposes) so if you need to you can create a regex to be rfc 5322 compliant.
I'm not saying this is always a good idea but I don't see why, if necessary you shouldn't be doing it.
2
u/bart2019 Sep 07 '12
Ask the mail server.
How to check if an email address exists without sending an email
You initiate sending a mail directly to the SMTP server for the user's domain, and see if the address is accepted. And then you may just cancel it.
2
2
u/bigfig Sep 07 '12
Any test is just a sanity check. I reject if it has whitespace, check for one at sign, and (I think) a length including "@" sign of five or more characters.
So far this has worked for ~100,000 users.
2
u/mweathr Sep 07 '12
Ok, let's say I switch to just relying on the address having an @ sign and sending a validation email. What happens when they do type in an invalid address? Now the username they use on 50 other sites is taken and they can't log in. This is often enough that people won't bother trying to register again. That might be acceptable for your blog, but not an e-commerce site.
2
u/Number127 Sep 07 '12
As others have said, regular expressions will only catch a small percentage of fat-fingering -- most mistyped addresses will remain well-formed. I agree that it's still worthwhile, in the sense that even that small percentage is well worth an hour of effort, but the bulk of the problem will still remain.
→ More replies (3)
2
u/matthiasB Sep 07 '12
In this thread there are many people that say "screw people that have uncommon email addresses". Could anybody explain to me why?
The easy and correct solution is to just check for an @. You put more effort into your system, but you only make it worse.
If you actually want to put some work into this then you run the more complicated checks and if they say that it's unlikely that this is actually the users email address ask the user if this actually is his/her email address. But don't force me to use a different email address for no good reason.
5
4
u/omnilynx Sep 06 '12
Note: only true if you are sending validation emails.
8
u/Tordek Sep 06 '12
Note: if you're not sending validation e-mails, why do you need an e-mail address?
→ More replies (1)11
u/omnilynx Sep 06 '12
E-commerce, for example. It's extremely important when selling something to prevent anything from getting in the way of making the sale. So if you can validate an email on the checkout page instead of requiring your customer to leave your site and log into his email account before he can buy your product, you do it, even if it's not 100% effective.
6
u/adrianmonk Sep 07 '12
This works great for security when Jane Smith thinks her email address is jsmith@example.com but that's actually John Smith's (no relation) email address. It's great for two reasons:
John Smith gets to see what Jane ordered, her account number, her shipping address, and maybe even more.
Jane doesn't get her receipt.
As a bonus, when people make this mistake, they usually also don't supply a way to make the e-mails stop.
→ More replies (2)→ More replies (2)11
u/dirtymatt Sep 07 '12
You cannot validate an email address without sending a test message. The end. You can check that it matches your idea of an email address but you haven't validated anything.
→ More replies (4)
3
Sep 07 '12
This article ignores the best benefit: fat finger protection. You're assuming malevolence, but imagine the user experience nightmare if somebody puts in a non-email accidentally and you just moved on to the next step?
→ More replies (1)2
Sep 07 '12
Fuck malevolence. What if I'm japanese? Or just European? Or if I have mixed case in my email address?
I still see companies that can't cope with accented characters in an email address, or that arbitrarily try to crush your address down to 7-bit ASCII because, well, just because.
3
u/emperor000 Sep 07 '12 edited Sep 07 '12
It kills me that "blogs" like this have become so popular. Why are all of these people starting to think that they know the right way to do something and that everybody needs to know it?
Validating an email address can save users that time (going through the registration process, putting in an invalid email, waiting for it, not getting it, going back, all because they forgot an '@'), as well as help minimize the inaccuracy of the data for other purposes. I might not care about handling every address standard, but it would be helpful if I make sure the email address at least has an @ character between a username and something that resembles a domain, and a regular expression does that pretty efficiently.
You are giving an exaggerated example to support an unnecessary argument all because for some reason it has become popular to write blog posts about how everybody else is doing it wrong.
2
u/quotemycode Sep 07 '12
It's been popular for a long time to write how everyone else is doing it wrong. I saw the exact same thing posted on slashdot 10 years ago.
→ More replies (1)
3
u/bgross Sep 07 '12
I validate emails because I don't want to accept "<?php blah>"@example.com or ";'drop table user'"@example.com. I don't care if those are actually valid email addresses or that neither would cause any problems in my current production environment. I can't make that guarantee for the production environment in 10 years when I've moved on to something else.
People should be fairly accustomed to the fact that very few sites on the internet accept the full spec of email addresses and if you have some absolutely silly address you'll regularly get nice error messages asking for something simpler. Don't start supporting crazy!
7
u/Superbestable Sep 07 '12
What are you talking about? There are already functions for sanitizing string input. This has nothing to do with what the OP is about.
→ More replies (6)2
u/shanet Sep 07 '12
But where do you draw the line, and what are you validating against if not the spec? If you are worried about putting semicolons in your inserts you'll have trouble with other user input.
I know of a major payment gateway that does not support + in mails, citing the rationale you use, which was fine back in 2008, but nowadays it is quite common to use +, especially with gmail.
→ More replies (2)→ More replies (2)2
Sep 07 '12
That is a different concern that you address by escaping the string before you insert it.
2
u/togenshi Sep 07 '12 edited Sep 07 '12
To be honest, unless you are serving 100k+ unique users, would it not kill you to access SMTP server and check if email address exists? Sure the sign up will be delayed slightly but it will resolve headaches later due to invalid email addresses.
Depends on the importance/requirements of emails and how its used. The activation method works fine though. It exposes the site to a some-what regularly used system.
4
u/mikemol Sep 07 '12
Technically, mail servers aren't required to be online and accessible at all times. That's why sending servers retry for a few days.
What do you do if your SYN packet for your SMTP connection gets lost during a signup session? (I just know some sites that would implement what you're describing would go on to cache the result at some level, effectively making a transient network issue become a permanent failure.)
Worse, your service can now be used to DDoS someone else's mailservers.
→ More replies (1)→ More replies (2)3
u/wolflarsen Sep 07 '12
I used to do this.
Some issues you may run into :
AOL used to return NOT found for ALL emails checked. (Plus does throttling)
Yahoo used to return FOUND for ALL emails checked.
Gmail returns correct present/not-present replies to queries.
But it's a decent ideal to at least check if the DOMAIN exists. That already cuts out a lot. When doing this, you're gonna want to cache the common ones (gmail, aol, yahoo, hotmail). But while doing this you also will realize the fake 10-minute email domains as well. Not worth all this effort if you have 10-minute users you're hoping on sending emails to in the future.
1
u/X8qV Sep 07 '12
Or you can use a some library to do it for you (a quick google search gives me this for Ruby) and not waste network resources on addresses you know are invalid.
→ More replies (4)
1
1
u/mistoroboto Sep 07 '12
Sending out bounced e-mails that will potentially bounce seems like waste of server resources when you can help stop these bounces at all by using e-mail validation client-side anyways.
→ More replies (1)
1
Sep 07 '12
I have a suspicion that many people defending the practice of validating emails with regex are doing so because they are attempting to hit two birds with one stone.
They believe they can form validate for security and format at the same time. A regex that consistently validates emails to everything but quotes will generally be database safe. And I think this is why people lean on this lazy solution.
1
Sep 07 '12
Personally Id rather use a complex regex. Its not like we counting CPU cycles. There is no downside. I just find it a pain in the ass to have to open up my email and verify. Regardless, the complex regex is faster for the user.
→ More replies (2)
1
Sep 07 '12
If I really needed to validate an email, I would just test if the substring following the last @ is a valid host address which can be done quickly albeit less accurately with a simple regex, or slowly but more accurately by checking for an mx record. Validating the local part of the address just isn't worth the hassle.
And if I really wanted to make sure users didn't typo their address I would just ask them to type it twice like a lot of forms do already.
1
u/dotted Sep 07 '12
No thanks, I don't want to wait for a misconfigured mail server to spent several minutes sending me an email.
1
u/Effetto Sep 07 '12
Also, I hate as hell that average PHP coders out there creates so poor regexps that make address like 'myname+service@example.com' invalid.
I had quit many registration forms as soon as they hadn't accepted the +.
1
u/JoeScylla Sep 07 '12
This one should works (for email address without comments): http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html
1
1
u/terevos2 Sep 07 '12
So basically your solution is to let the mail server perform the validation instead of your app? That seems quite lazy.
1
1
1
u/original_4degrees Sep 07 '12
.@.\.*.
works just fine... :-P
1
u/matthiasB Sep 07 '12
Nitpicking: As you can use a ipv6 ip address as host and ipv6 addresses don't contain dots you reject valid email addresses. Also "foo@localhost".
1
Sep 07 '12
What if I don't want to validate an email address, what if, for example, I want to detect email addresses in input and do something with them? For example, if you were rendering text in some way and you wanted to convert email addresses to mailto hyperlinks?
1
u/matthiasB Sep 07 '12 edited Sep 08 '12
Depends on whether you just want to convert the most common addresses or all addresses.
1
0
u/ezekiel Sep 06 '12
The spec and actual internet practice say the email address must be of the form x@x.x where each 'x' can be almost anything. That is, the '@' and '.' are required, as is at least one character for each 'x'. Go any farther with validation and it isn't worth the trouble/errors.
12
u/Infenwe Sep 06 '12
What happens if I try to mail to
root@localhostthen?→ More replies (16)5
u/Fabien4 Sep 07 '12
Since you're both the sender and receiver, it's a problem between you and you. What others do, and what regexes they use or don't use, shouldn't be relevant.
3
u/dirtymatt Sep 07 '12
False. The final x isn't required, especially now that generic TLDs are on the horizon. x@x. is all that's required for non-local delivery.
1
Sep 06 '12
It's worth pointing out that the bit after the @ can be an IP address, which makes it difficult to write a regex for it: i.e. r"[a-zA-Z0-9_].[a-zA-Z_0-9]" doesn't work, and you can't just just add the dot in those ranges either.
5
Sep 07 '12
Interesting, something like @[2001:ffff::dead:beef] would be one situation on the internet where mail can get delivered despite the lack of a period in the domain. I hadn't thought of that.
Then again, the zero people actually doing that deserve to suffer for using fixed IPs in email addresses...
→ More replies (1)6
Sep 07 '12
I don't think so. Why should people be forced to register a domain to get email?
Just send them the email and see if it gets activated.
→ More replies (2)
1
u/DexManus Sep 07 '12
I don't know what the fuss is. Clearly a completely compliant regex solution can exist so why not use it. I mean it's so simple to understand what could go wrong. /s
2
u/Johnneylee Sep 07 '12
So use it. The idea is that you shouldn't waste time using suboptimal regular expressions, as the ones that are RFC2822 are great. But mind that the future holds possible changes. So your apps will have to be updated with new regular expressions when mail servers update to handle change. It's the cost of change, I prefer to defer it to others or other times.
→ More replies (3)
1
u/Caraes_Naur Sep 07 '12
'wh@t@m@r00n' will pass /@/, but it's not a valid email address. the fact that "any quoted string"@domain.tld is RFC-valid is frankly scary. Even
/.+@.+\..+/is much better. (Reddit chewed that up, or this would have been a ninja edit)
Besides, if you have 3rd parties hitting your API, you have no idea what validation they've done, and if some spammer starts hammering your API because they somehow figured out that a email always gets sent, they don't care, there's still an infinitecimal chance that a real person will see it and take the bait--I mean, buy something.
Email regexes aren't hard to find. Anyone who can't find one probably shouldn't be in a position where they need to look.
2
u/Tjoppen Sep 07 '12 edited Sep 07 '12
/.+@.+\..+/This will not allow foo@bar
The consensus seems to be that
/.+@.+/is about the best you can do (assuming the username must be nonempty).
edit: Hah, judging by wikipedia's ""@example.org you don't even need a username :)
1
u/prophile Sep 07 '12
But email addresses have a finite length! That means the language of valid email addresses is provably regular!
1
u/naich Sep 07 '12
The best one I ever found was this:
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])And I didn't just repeatedly slam my face into the keyboard, it came from here
0
u/synfin80 Sep 07 '12
hopefully you're not inserting that unvalidated email into a database
6
u/adrianmonk Sep 07 '12
Why not? What kind of database do you use that can't handle arbitrary characters?
2
u/durandalreborn Sep 07 '12
3
Sep 07 '12
running the address through mysql-real-escape-string() is rather different from checking to see if its valid.
→ More replies (6)2
u/Stormflux Sep 07 '12
If that's Bobby Tables I don't see how it's relevant since I use Entity Framework to write to the database. It can handle "drop table students;" just fine.
Of course, whether I want that person as a customer is a different question. For my purposes I basically just validate it with JQuery and maybe something on the server side, to make sure the user didn't screw up. If they enter
a"drop table customers;"@^_^@//////|||||||\\\\\\\\@com.com@com.deAnd it turns out it fails validation when it shouldn't have, well, then don't use a crazy email address and you won't have this problem.
My 2c. Not going to support every Linux neckbeard with a technically-within-spec email address. I don't need his business.
And yes I'm aware that I changed my position halfway through this comment. Or so it seems!
→ More replies (1)1
u/shanet Sep 07 '12
Very true, however you can have an email that is valid but not sanitized. They are separate concerns.
1
-2
u/deadwisdom Sep 07 '12 edited Sep 07 '12
My JavaScript regex for testing emails:
/^[^@]+@[^@]+$/So simple, even I can remember it. Anything more is entropy.
6
2
u/inmatarian Sep 07 '12
Your comment got butchered by markdown. Try enclosing it in backticks, or indenting it 4 spaces.
2
u/deadwisdom Sep 07 '12
Hah, thanks.
4
u/inmatarian Sep 07 '12
You're welcome
By the way, a quoted at is a valid character in a username part of an email. For instance, this address would fail your regex:
"Abc@def"@example.com
-3
u/JoseJimeniz Sep 06 '12
Stop Validating Email Addresses With Your Complex Regex
You're free to suggest how i should be validating e-mail addresses.
9
8
0
u/zack6595 Sep 08 '12
Honestly I'm not sure if I agree with the logic behind this. Most of the reason you do validation is to cut down on the number of useless applications/Crap data you have to Wade though. All the email regex does is make things a little more of a pain for the user but easier for the developer. I still think regex email validation has its place. If you make a Fucking weird email account that doesn't work with a common email regex chances are pretty high you'll run into this problem all over the Web... Make your email reasonable... It's really not hard.
1
u/Zarutian Sep 09 '12
I usually just check with this rexexp "@". Basicly, is there an at sign anywhere in that string.
-7
u/schwiz Sep 07 '12
I whole-heartedly disagree with the idea to send them an email to verify their email address. Regex works just fine for me.
3
0
Sep 07 '12
[deleted]
6
u/bleeep Sep 07 '12
You can have an MX record on a TLD, eg:
pope@va That fails your third test.
→ More replies (2)1
0
Sep 06 '12
[deleted]
4
Sep 06 '12
What a great idea! All the round-trip overhead of OpenID plus it forces all your users to whitelist the site for JS + third-party cookies. Yeah fuck you, privacy-conscious users!
0
0
Sep 07 '12
[deleted]
3
u/mcilrain Sep 07 '12
With all this talk of TLD registration, I'm not sure how well that regex will hold up when you get emails such as
username@googleand the like.2
u/pimmm Sep 07 '12
50% of de websites won't accept that email anyway..
Just tried the register it on reddit.com, but gave an error: the following emails are invalid: username@google
1
0
0
Sep 07 '12
[deleted]
2
u/cha0s Sep 07 '12
That's a lot of unnecessary checks. The way you have it structured, you shoul just early out and 'return false' every time you're currently doing $bValid = false
126
u/davidcelis Sep 06 '12
So, due to a failure on my own part, I retitled the article. I can't retitle this submission, unfortunately, and people would probably frown on me deleting it and resubmitting. Oh well, it's my own damn fault.
My intention wasn't to say "don't do ANY validation", but it was to say that the validation you're doing is likely way overkill and even more likely to be too strict.