To this point, there’s a website dedicated to the subject. Some of the regexes get pretty wild…
You can use symbols like [ ] . { } ~ = | $ in the local-part (bit before the @) of email addresses. They’re all perfectly valid but a lot of email validators reject them. You can even use spaces as long as it’s using quotation marks, like “hello world”@example.com
.
A lot of validators try to do too much. Just strip spaces from the start and end, look for an @
and a .
, and send an email to it to validate it. You don’t really care if the email address looks valid; you just care whether it can actually receive email, so that’s what you should be testing for.
darkpanda@lemmy.world 10 months ago
tomi000@lemmy.world 10 months ago
Yea but most of the time its more important to block code injection than to have the last promille of valid mail adresses be accepted.
dan@upvote.au 10 months ago
You’re not going to get code injection via an email address field. Just make sure you’re using prepared statements (if you’re using a SQL database) and that you properly escape the email if you output it to a HTML page.
ChaoticNeutralCzech@feddit.de 10 months ago
I think emailregex.com offers best of both worlds.
douglasg14b@lemmy.world 10 months ago
Don’t forget +
Super handy with Google email.
itsralC@lemm.ee 10 months ago
Not even a dot: TLDs are valid email domains. joe@google is a correct address.
RubberElectrons@lemmy.world 10 months ago
Mmm… That doesn’t seem right, it’s usually gotta be fully expanded to at least a particular A record/MX.
How would you tie the tld itself to an MX?
TwitchingCheese@lemmy.world 10 months ago
TLD is just another DNS layer, try an SOA or NS lookup for “com.” those are obviously hosted somewhere. Hell the “.” at the end is even another layer with the root nameservers. You’d probably trip up a bunch of systems that filter on common convention rather than the actual RFC, but you could do it.
RubberElectrons@lemmy.world 10 months ago
How the hell were the original rfc designers so creative as to result in such a flexible system?? It’s gets crazier the more you look at it.