Live data from Hacker News

Stop Validating Email Addresses With Your Complex Regex

davidcel.is

91–100 of 211 posts

Re: Stop Validating Email Addresses With Your Complex Regex

#91
post #34

The question is why people are validating the email in the first place. * to ensure it is deliverable? Well, then you better send them an email. * to let people know when they misread the labels and put something that was clearly not an email in the email field? A simple check for an at-sign is usually sufficient. * because some tester opens a ticket saying you can enter an invalid email in the email field? Yeah, tha…

Only ticket I've ever seen about email validation was that a webapp was refusing to accept a customer's valid (and already registered/paying money in another system) address.

Re: Stop Validating Email Addresses With Your Complex Regex

#93
post #33

My goto for email validation is /^.+?@.+?\..+?$/ Incase I've typed it wrong, that should basically work for anything that contains at least one @ and one dot, in that order, as well as at least one character at beginning, middle and end. It's served me well thusfar. Edit for clarification: The reason I prefer this over just checking for an @ is that if you're just checking for @ a common mistake like "me@hotmail,com"…

My favorite: /.\@.*\../ It should be similar to your version, but only matches just enough parts that require for email validation (i.e. "o@example.c" part of foo@example.com).

[deleted]

Re: Stop Validating Email Addresses With Your Complex Regex

#94
post #76

Earlier quoted context omitted.

Because it takes system resources to deliver email. Furthermore, if people make a simple typo, why go to the extent of attempting to send something to it when it's obvious?

Because it's not obvious. Ask developers to recite the rules for correct email address, and most of them will get it laughably wrong. I blame the standard, which is far more "featureful" than is actually required, but that is the way it is.

It's featureful because it's old. Who routes email to UUCP any more? Just look at the sections of 5322 that are devoted to "Obsolete Syntax".

Re: Stop Validating Email Addresses With Your Complex Regex

#95
I wish more sites would use a validation email. I get a good number of emails for people that have my (real) name but use my email address on gmail (since I have the same name) to sign up when they don't want to recieve emails from the site. Thus I get to enjoy them. When the site sends a validation email I just ignore it and never hear from them again.

As a side note, be cautious of using such a tactic. I have recieved their logins, CC and Physcial Address information because of this.

Re: Stop Validating Email Addresses With Your Complex Regex

#96
post #37
post #30

Earlier quoted context omitted.

I understand the argument re validating email addresses passively (regex, no regex, etc.) vs actively (send an email by SMTP). What I don't understand with this ever-repeating discussion is why the complexity has to be visible. e.g. > > Yeesh. Is something that complex really necessary? Many functions are complex - we put those in libraries, pushing them under the hood, and move on. What is so special about parsing e…

Plus a Large Regex for mail validation is not supposed to be heavily used. It's supposed to be used once at registration for example. So why would it matter if it's slow/heavy/...

Maybe it is less resource-intensive to actually send an email rather than use a heavy regex to validate the email?

Re: Stop Validating Email Addresses With Your Complex Regex

#97

I don't think this is good advice. From a previous startup we saw a ton of signups like, "john@gmail" and the like. Obviously this person will not get a validation email -- and in all likelihood will not be able to log in to his account when he returns. It's best to catch him when he's entering the information.

still there is a difference between validating * @ * . * and trying to check if parenthesis are matched correctly.

Re: Stop Validating Email Addresses With Your Complex Regex

#98

Amen! Anyone else here use myemail+token@gmail.com when they have to register with their email to find out who is selling them out and to make spam filters easier? It still amazes me that 70% of the places I attempt using foo+bar@gmail.com call it invalid. And that does not even begin to touch the myriad valid permutations that are "invalid" out there.

And likewise, it amazes me that people think that for all their efforts at combating filters, captchas and the like, that the most nefarious of spammers aren't stripping off "+token"s from email addresses.

Re: Stop Validating Email Addresses With Your Complex Regex

#99
post #9
post #6

I would rather lose a few users through a faulty regexp than lose double digit percentage through an email activation step.

No regexp in the world will tell you if an email address is real.

Of course - I doubt anyone (smart) has ever claimed that to be the case.

However, they can, if implemented correctly, tell you if the email address is syntactically valid.

Re: Stop Validating Email Addresses With Your Complex Regex

#100
Oh the irony. His suggested Regex is not even correct.

    /.+@.+\..+/i
A trailing dot is valid at the end of a domain name. These domains are said to be fully qualified.

http://www.dns-sd.org/TrailingDotsInDomainNames.html

This also potentially eschews internal deployment.

His other suggesiton, /@/, at least, is not harmful, but there are validators based on the RFC that do the job for most platforms.

Validating the address may provide useful feedback to users who accidentally mistyped something, invalidating the permise of his last paragraph.

.

/someone is wrong on the internet.

Post reply on HN