Live data from Hacker News

It's Impossible to Validate an Email Address

elliot.land

21–30 of 68 posts

Re: It's Impossible to Validate an Email Address

#21
post #11

If you were to ask me for a regex, I'd say /.+@.+/. That's the easiest and most accurate way to do it by regex. Sure, some invalid addresses may still get accepted, but that is unavoidable. Even the most thorough validation[0] is going to accept nonexistent addresses. [0] Except those that validate by sending a mail to it. Sending an email is the only way to be sure.

    # get email addresses
    grep -EiEio '\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b'

    # censor email addresses
    sed -r 's/()/\1--removed--\2/g'
If email doesn't meet those, I drop them on the floor. Then again, I drop email on the floor for lesser reasons.

Re: It's Impossible to Validate an Email Address

#23
post #12

I once heard the story of a man who helped Aruba set up their DNS (.aw) in the late 90's. In exchange, as part of his compensation, he asked for an email address at the top-level domain, and received something like js@aw, which is a perfectly functional email address, but trips up a lot of validators.

It isn't a valid address. TLDs must not resolve, so it should be impossible to make a server handle it (yet, it is mostly possible, because most DNS servers do not completely implement the RFCs - still, there's no guarantee it will work on every network).

Re: It's Impossible to Validate an Email Address

#25
post #6

I think that spaces are also valid in email addresses. So, even would be a valid email address in that case...

They are valid within quotes, so that is valid, but isn't.

Almost anything is valid within quotes, but quotes can not appear everywhere.

Re: It's Impossible to Validate an Email Address

#26
post #19

What I'm about to say is more general than regex, but can online services please stop trying to validate my email address? If I gave you an email address that you think is invalid, rest assured I did it for a reason. I'm not an imbecile: I know how to type my address correctly (especially when you make me type it twice). For all the imbeciles who don't know how to type their address correctly, the phone system still…

https://medium.com/i-m-h-o/please-stop-verifying-my-email-ad...

I wrote something about this a while ago. I'm no wordsmith but it fits here.

Re: It's Impossible to Validate an Email Address

#27
post #11

If you were to ask me for a regex, I'd say /.+@.+/. That's the easiest and most accurate way to do it by regex. Sure, some invalid addresses may still get accepted, but that is unavoidable. Even the most thorough validation[0] is going to accept nonexistent addresses. [0] Except those that validate by sending a mail to it. Sending an email is the only way to be sure.

That is the only correct answer.

    .+@.+
In human language: an email address consists of something, an @, and something.

That's it. The name part can be anything; so don't validate it beyond having a character.

We don't have one-character domains yet, but there is no reason to exclude them. It is already possible to arrange your own top-level domain if your pockets are deep enough (.google), so don't be surprised if some megacorp starts using a top-level domain without any subdomains. Don't validate the domain part beyond having a character.

Re: It's Impossible to Validate an Email Address

#28
I remember reading the opinion that one need only verify that an email address is an email address by answering, "Does it have an '@'?". Yes? Email address. No? Try again.

Perhaps it is nice to ask a question one step above the email verification: How much responsibility does//should the user have, how much responsibility does//should the designer have, in ensuring the user's email address as valid?

Re: It's Impossible to Validate an Email Address

#29
post #15

Let's remind the famous quote from Jamie Zawinski: "Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems." I was neglecting this quote for a long time, until I started using regular expressions in real projects...

I never really learned how to write regex. I can write simple ones with the use of a tool to help me figure out what I need to write (and a cheatsheet to explain the terms).

I realize they could save me some future potential grief, but I'm usually more concerned with the present actual grief they cause me.

I feel like I'm letting down the side.

Re: It's Impossible to Validate an Email Address

#30
post #19

What I'm about to say is more general than regex, but can online services please stop trying to validate my email address? If I gave you an email address that you think is invalid, rest assured I did it for a reason. I'm not an imbecile: I know how to type my address correctly (especially when you make me type it twice). For all the imbeciles who don't know how to type their address correctly, the phone system still…

Agreed. I find things like "youdont@needmyemail.com" usually work, and then if they ever bother to read what’s in their database they may get a hint.
Post reply on HN