4 ms·
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 acce
by mcv 11y ago
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.
- LinuxBender 11y ago# 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.
- lstamour 11y agoSo 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. :)
- LinuxBender 11y agoYes. Actually for the longest time I rejected the connection with "Your name is too awesome!"
- Symbiote 11y agoSo 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.
- LinuxBender 11y agoYes.
- mcv 11y agoThis 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.
- Freak_NL 11y agoThat 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.
- s_kilk 11y ago> If you were to ask me for a regex, I'd say /.+@.+/ How about "one@two@three@four@example.com"?
- ketralnis 11y agoYes there are loads of invalid email addresses it allows. It's not supposed to be perfect.
- Freak_NL 11y agoYeah, 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.
- mcv 11y agoAny validation is also going to allow "someonewhodoesntexist@nonexistentdomain.com", unless you send an email to it.
- userbinator 11y agoSending 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.