News for hackers. Stuff that matters.
Re:It's Impossible to Validate an Email Address by mcv on Sunday April 03, 2016 @10:33AM (#11416221)
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.

Re:It's Impossible to Validate an Email Address by Freak_NL on Sunday April 03, 2016 @11:58AM (#11416535)
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 by userbinator on Sunday April 03, 2016 @12:20PM (#11416606)
Sending an email is the only way to be sure.

Absolutely this. The check for an '@' and something before/after it is for sanity, and anything beyond that would involve actually trying to use the address.

Re:It's Impossible to Validate an Email Address by s_kilk on Sunday April 03, 2016 @12:18PM (#11416597)
> If you were to ask me for a regex, I'd say /.+@.+/

How about "one@two@three@[email protected]"?

Re:It's Impossible to Validate an Email Address by mcv on Monday April 04, 2016 @03:58AM (#11420132)
Any validation is also going to allow "[email protected]", unless you send an email to it.
Re:It's Impossible to Validate an Email Address by ketralnis on Sunday April 03, 2016 @12:24PM (#11416622)
Yes there are loads of invalid email addresses it allows. It's not supposed to be perfect.
Re:It's Impossible to Validate an Email Address by Freak_NL on Sunday April 03, 2016 @12:44PM (#11416706)
Yeah, the point of checking for the @ is chiefly to prevent inexperienced users (e.g., elderly) from entering the wrong type of data. For example, enter a line from their postal address instead of their email address.
Re:It's Impossible to Validate an Email Address by LinuxBender on Sunday April 03, 2016 @11:27AM (#11416432)

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

    # censor email addresses
    sed -r 's/(<)[[:alpha:][:digit:]\._%\+-]+@[[:alpha:][:digit:]\.-]+\.[[:alpha:]]{2,4}(>)/\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 by Symbiote on Sunday April 03, 2016 @12:19PM (#11416603)
So you're blocking email from your local .museum, from anyone who has an Irish name like O'Connor, all international TLDs, and most newer TLDs.
Re:It's Impossible to Validate an Email Address by LinuxBender on Monday April 04, 2016 @09:53AM (#11421850)
Yes.
Re:It's Impossible to Validate an Email Address by lstamour on Sunday April 03, 2016 @12:13PM (#11416582)
So any new gtld longer than four characters would be dropped on the floor? E.g. .software? If you're trying to censor email addresses from a file, that doesn't work that well. :)
Re:It's Impossible to Validate an Email Address by LinuxBender on Monday April 04, 2016 @09:53AM (#11421848)
Yes. Actually for the longest time I rejected the connection with "Your name is too awesome!"
Re:It's Impossible to Validate an Email Address by mcv on Monday April 04, 2016 @04:01AM (#11420144)
This would not allow email addresses with an = in them, which I've had. The point of my overly tolerant regex is exactly that: any more restrictive validation is going to drop some perfectly legal email addresses. Sending an email is the only way to be sure.