Live data from Hacker News

Stop Validating Email Addresses with Regex (2012)

davidcel.is

101–110 of 228 posts

Re: Stop Validating Email Addresses with Regex (2012)

#102
post #11
post #2

I appreciate the idea here but generally you set a non perfect regex expression and just roll on with whatever other verification there is (send email). Well I don’t but if you did I don’t see much harm. I won’t ask people to type the email twice, that’s just annoying.

And it becomes super annoying when you can't paste into the second field. Had to implement this once - should have rage quit immediately.

Agreed, also anything that defeats a password manager is a red flag for me. I've seen sites that break a password manager's autofill AND disallow pasting a password. It's like they want me to use a bad password.

Re: Stop Validating Email Addresses with Regex (2012)

#105
You can validate the field with whatever you want. It's going to be your data that you have to deal with later. Don't want users to use comments in emails? Don't validate them.

There is not reason whatsoever to validate to a standard just because it's a standard. Validate to what you will support.

Re: Stop Validating Email Addresses with Regex (2012)

#107

This won't be popular, but: 1. An experienced dev just killed 54k stars on GitHub due to pressing a button in an auto-pilot mode. Do you think a Joe High who wants to give you $100 won't ever type '2' instead of '@'? What about an old lady? Or someone with physical difficulties? Have you personally ever made a typo in an email? 2. That code in the article is not color highlighted (rainbowed for Regex) or formatted pr…

>You won't need to edit it for 20 years

I won't bet my life on it but probably some other sucker will have to fix it. This happened to me where I found a regex that was validating urls was incorrect after urls were allowed to contain unicode stuff (I do not remember the details just that we had an url from a customer that contained arabic looking characters)

IMO the language standard library should include this stuff of validating stuff to avoid developers copy pasting dubious quality regex from Stack Overflow

Re: Stop Validating Email Addresses with Regex (2012)

#108
post #96

Validate emails in a manner that is representative of the typical use of your service. If it’s a specialist email processing tool, then you should probably follow an RFC. If it’s a dating app, you can probably just use a regex that covers common cases to help users avoid typos. I think the decision is similar to the one picking how modern are the browsers you are going to support. It’s a trade-off. That’s my take on…

You will want to check ownership by sending a verification email anyway. If you want to avoid typos, show a "are you sure... yes/no" warning, there is no need to block anybody. Typos will overwhelmingly lead to valid-looking addresses anyway.

I agree, but there are all kinds of scenarios where you might need to simply answer a question - “is this an email address, and does it look valid?”.

I needed to do just that once - I was given a flat file with some bulk export data that came from some other system that I had no exposure to and needed to clean up contact data by figuring out what was what, separating names from phone numbers, from postal addresses, from emails, etc. It just needed some rate of success, not to be perfect.

Lets not assume that we always know what people are trying to do and what is the best way to do it. Devil is in the details.

Re: Stop Validating Email Addresses with Regex (2012)

#109

Does anyone on HN have any of these "surprising" email addresses that most people and developers do not expect? How does it work with common e-mail clients? How do people react when you show/tell them your email? I have a domain that uses non-ascii characters, and while I can receive emails on that domain, hosted by Fastmail, Fastmail clients refuses to _send_ emails to that domain (I can, if I type the domain as Pun…

> Does anyone on HN have any of these "surprising" email addresses that most people and developers do not expect?

I do

> How does it work with common e-mail clients?

Perfectly

> How do people react when you show/tell them your email?

With confusion, so it requires some gentle insistence that I know my own email address.

Re: Stop Validating Email Addresses with Regex (2012)

#110
post #17

RFCs for email addresses are cool, but on the web we have our own standards! https://html.spec.whatwg.org/multipage/input.html#valid-e-ma... "This requirement is a willful violation of RFC 5322, which defines a syntax for email addresses that is simultaneously too strict (before the "@" character), too vague (after the "@" character), and too lax (allowing comments, whitespace characters, and quoted strings in manner…

If you really want to take validation seriously, why not add a human element to it, and not design one line of code to try to fix everything?

One of the biggest problems with email input is typos -- and there are some very common typos that could easily be accounted for with code. For example foo@gmail.co, foo@gmial.com, foo@comcast, etc.

It should be common, when these types of typos occur, to prompt the user to fix them. Unfortunately, this is quite rare.

Post reply on HN