Live data from Hacker News

Stop Validating Email Addresses With Your Complex Regex

davidcel.is

181–190 of 211 posts

Re: Stop Validating Email Addresses With Your Complex Regex

#181

Earlier quoted context omitted.

Why does it matter? If I managed to acquire the 8.8.8.0/24 netblock, I might very well want to use 'user@8.8.8.8' as my e-mail address. I don't see why it has any material affect on someone requesting e-mail addresses: if it's valid, then it's valid. This seems to be an example of the misplaced sense of propriety with which people approach validating e-mail addresses -- that somehow, your job isn't just to help the u…

The crappy regex solution is much faster than what you suggest, and will work 99.9% of the time. The time you spend doing it the right way will reduce your conversion rate because people will view your site as slow. In this case worse is better.

> The time you spend doing it the right way will reduce your conversion rate because people will view your site as slow.

During all those new account registrations they're constantly making?

Does this feel slow to you? https://www.emailitin.com/email_validator

> In this case worse is better.

No, it's not. Every time you exclude a valid e-mail address, you lose or annoy a customer for no reason other than your own lack of understanding of the RFCs.

There are a number of steps that can be taken that don't involve broken regexps that filter out valid addresses. Please stop trying to justify doing it completely incorrectly.

Re: Stop Validating Email Addresses With Your Complex Regex

#182

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.

I used to use mail@mikeash.com as my primary e-mail address. Enough sites rejected that (due to thinking that "mail" was bogus somehow) that I eventually switched to mike@mikeash.com.

Re: Stop Validating Email Addresses With Your Complex Regex

#183

Earlier quoted context omitted.

> Hopefully that's not the SMTP syntax you're actually using. I typed it out live. I'm not an SMTP client and I don't have the RFCs memorized. > I'd reject (give you a 5xx) that from my mail server for those reasons alone. Postfix accepts it. I haven't checked the RFC to verify your concerns, but assuming they're correct, then my expectation is that postfix is liberal in what it accepts because A) it's a good idea, a…

Postfix (and the other big receivers) will ignore it, but will send using the proper RFCs. It's still a good sign of a badly written bulk mail engine, and worth rejecting for.

> It's still a good sign of a badly written bulk mail engine, and worth rejecting for.

No, it might be worth scoring the e-mail with a spam filter, but the MTA shouldn't be overzealously throwing away e-mail.

Re: Stop Validating Email Addresses With Your Complex Regex

#184

You'll hurt your email reputation if you send too many emails that bounce. It's worth checking everything you can before firing off an email. This includes using a decent regex and doing a lookup on the domain to make sure they have an MX record. While technically you can have a mail server with no MX record (it falls back to sending to the A record), you won't find too many mail servers configured that way in the wi…

Also, instead of just failing to allow the email address, you could warn the user that what they entered doesn't appear to be valid, and that they should double check the address.

Re: Stop Validating Email Addresses With Your Complex Regex

#186

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.

I love these articles that are posted and the ACCURATE answer is that the article proposes bad advice. In what world is not validating an email a good thing? It's not like emails vary after a certain complexity is reached. A better article would have been someone documenting a validation regex that approaches perfect without exceeding insane complexity. Next we'll see articles to not run the Luhn algorithm on credit…

I regularly run into email fields that won't accept +. This is just an extension of that thinking.

Re: Stop Validating Email Addresses With Your Complex Regex

#187

This has come up so often on Hacker News that I decided to create a very simple JSON API for checking email addresses. Free to use for anyone. Performs the right regexp check for email addresses based on RFC-5321 rules (not the oft-quoted but incorrect RFC-822 rules, which are for mail headers), performs MX lookups to ensure mail can be delivered, and performs the same "did you mean" type checks that kicksend's mailc…

If I type name@outlok.com instead of name@outlook.com, it says the email is valid - when in fact it is not.

Who says it's not valid?

Re: Stop Validating Email Addresses With Your Complex Regex

#188
post #37

Earlier quoted context omitted.

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?

I really don't think so since you're soliciting an email server while a regex is just some code that has to be run, and they are run on a tiny string (a mail is never really long).

Also it's bothering for the user, if you need mail confirmation then do it, but otherwise it should be a RULE OF THUMB to always avoid annoying user. Thus avoid mail confirmation.

This article is actually a really bad advice. I don't know why it's upvoted so much.

Re: Stop Validating Email Addresses With Your Complex Regex

#189

Earlier quoted context omitted.

The crappy regex solution is much faster than what you suggest, and will work 99.9% of the time. The time you spend doing it the right way will reduce your conversion rate because people will view your site as slow. In this case worse is better.

> The time you spend doing it the right way will reduce your conversion rate because people will view your site as slow. During all those new account registrations they're constantly making? Does this feel slow to you? https://www.emailitin.com/email_validator > In this case worse is better. No, it's not. Every time you exclude a valid e-mail address, you lose or annoy a customer for no reason other than your own lac…

Does this feel slow to you? https://www.emailitin.com/email_validator

Yes, it did.

Re: Stop Validating Email Addresses With Your Complex Regex

#190

Earlier quoted context omitted.

> The time you spend doing it the right way will reduce your conversion rate because people will view your site as slow. During all those new account registrations they're constantly making? Does this feel slow to you? https://www.emailitin.com/email_validator > In this case worse is better. No, it's not. Every time you exclude a valid e-mail address, you lose or annoy a customer for no reason other than your own lac…

Does this feel slow to you? https://www.emailitin.com/email_validator Yes, it did.

I got a response in 55ms. We must have different definitions of 'slow'.
Post reply on HN