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.
> If you were to ask me for a regex, I'd say /.+@.+/ How about "one@two@three@four@example.com"?
It's Impossible to Validate an Email Address
61–68 of 68 posts
Re: It's Impossible to Validate an Email Address
#62If 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
#63Earlier quoted context omitted.
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).
The first one I found that does resolve: http://ai./ It has an MX record too. There is nothing wrong with this.
What is wrong with it is, amongst other things, the real-world possibility of colliding with internal hostnames.
Re: It's Impossible to Validate an Email Address
#64Earlier quoted context omitted.
# 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.
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
#65Earlier quoted context omitted.
# 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.
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
#66Wouldn't it be reasonable to have a sanity check that can be bypassed by the user? It is very likely to be a mistake if there's no full stop in the address, but there are exceptions [0]. I would like to see a warning if I accidentally type vostok@examplecom instead of vostok@example.com. [0] https://mail.gnome.org/archives/evolution-list/2002-January/...
Re: It's Impossible to Validate an Email Address
#67If you happen to control the web page where the user is entering the email, this little piece of code has been a godsend for us: https://github.com/mailcheck/mailcheck I agree with the idea that it's impossible to validate. But, mailcheck takes the approach of seeing if the email is potentially wrong, then prompting the user with what it thinks they meant. It's usually right, but if not, it allows whatever the user w…
This kind of stuff is great - make suggestions, but allow it to go through even if you think it's wrong. For the last email validation I worked on, there were only 2 absolute blockers - there must be an @ sign, and the domain must have MX records (emails that are technically valid remain useless if we can't send them anything). There were a number of other checks (being close to yahoo.com or gmail.com or other common…
Technically, the RFC(5321) says MX records aren't required. You may be throwing out some small number of valid emails.
"If an empty list of MXs is returned, the address is treated as if it was associated with an implicit MX RR with a preference of 0"
Re: It's Impossible to Validate an Email Address
#68For anyone who would like to test their email address validation code, I wrote a fuzzer which can generate syntactically valid addresses (among other things). https://github.com/nradov/abnffuzzer
Is there ABNF for email addresses in an RFC?