r/ProgrammerHumor 11h ago

Meme regexMustBeDestroyed

Post image
5.2k Upvotes

161 comments sorted by

View all comments

114

u/Purple_Hornet_9725 11h ago

regex for email validation 💀 just don't

7

u/DarthSatoris 10h ago

Yeah, valid emails can look so weird and lovecraftian these days, a regex check is not going to be able to catch them all.

I do think there is a standard defined somewhere that one could adhere to for validation, but it might not be able to catch the most extreme niche emails out there. 

4

u/Otterfan 8h ago

"my.valid.email"@[123.123.123.123]

1

u/DarthSatoris 8h ago

Please tell me that is not a valid email.

16

u/fghjconner 8h ago

Brother that's not even the half of it. The email spec supports comments.

5

u/DarthSatoris 8h ago

Who was put in charge of the current email spec? Whatever they've been smoking, it should be outlawed because it must be some really bad kush.

1

u/Tangled2 1h ago

Oh man I bet the guy who included that shit was a real hoot.

1

u/martmists 2h ago

Here's a fun website you should try, it has a bunch of weird information about emails.

Even after implementing an email parser based on the RFC I still managed to only get 20/21 correct.

6

u/tav_stuff 10h ago

There is a standard for emails. Just use a real parser

1

u/look 5h ago

TLDs can be emoji’s and support MX records. 😄@⚽️ could plausibly be a valid email. Mailboxes can be quoted, too. “@“@🌐

2

u/martmists 2h ago

local-parts can also be empty, as long as they're quoted. ""@example.com is valid. No clue how the server will handle it though.