Re:Ruby's Email Address Regexp
by ghayes on Tuesday January 04, 2022 @10:04PM
(#29804509)
The regex listed there isn’t that much more complex. It’s basically a check for *@a*.* where * is some minimal whitelist of valid characters and a is an alphanumeric to start the domain name.
[ Parent
| on HN ]
Re:Ruby's Email Address Regexp
by merlinscholz on Tuesday January 04, 2022 @10:15PM
(#29804594)
And even though that sounds reasonable, it is still wrong. Technically, you do not even need the dot, if you add an MX record to a whole TLD or have some other funky DNS setup.
Re:Ruby's Email Address Regexp
by ameliaquining on Tuesday January 04, 2022 @10:40PM
(#29804824)
I'll quote the WHATWG HTML spec, which that Ruby code cites as its source (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 manners unfamiliar to most users) to be of practical use here.
Personally, I say if it's good enough for Web browsers, it's probably good enough for your app.
The linked regexp doesn't require the TLD: https://rubular.com/r/Y9G4HR2Ox8gzqd
Yep! I know that @mil addresses used to be a thing. With the explosion of new TLDs I would be unsurprised if name@gmail addresses became a thing in the future and silly devs handled it by adding an exception to their huge regex instead of just using “.+@.+”.