me: i need to validate some email addresses, so i am going to write a quick regex. how hard can it be?
*4 hours later*
me. i now have 2 problems and one of them is that I've accidentally summoned an ancient daemon. wht the actual fuck
me: i need to validate some email addresses, so i am going to write a quick regex. how hard can it be?
*4 hours later*
me. i now have 2 problems and one of them is that I've accidentally summoned an ancient daemon. wht the actual fuck

@meeper JavaScript you say? The same person covered that too. This one made me want to punch my computer.
Copy a relatively good existing one, then just prompt for "are you sure" if it fails to match.
@nixCraft If we ever get a Ten Commandments for programming, one of them should be:
"Thou shalt not write thy own email regex."
Did you find the needle in the haystack yet? /s
@nixCraft Either you use something simple like .*@.*\..* (at least an at-sign and a dot after it) and send an e-mail with an link or you will summon a debate war on if the complete e-mail standards should be followed or not.
And, if you choose to follow the standards, I have to warn you (and I guess some people had warned you already) that most e-mail servers do not follow the standard (like Cloudflare).
On the other hand, I just sent a message from "example+';DROP/**/TABLE/**/users;#"@gmail.com to example@some-domain-of-mine and it arrived. I hope you never need to deal with addresses like those.
At least the ancient demon is bound to serve you, and not eat you until it provides you with a perfect email parsing library, right?
@nixCraft Everytime someone uses a regex to validate an email, god kills truckloads of kittens
Split on last @ ensuring the previous character is not itself an @
Check if the domain part resolves, make sure you allow for international domain names.
You can check if the localpart is well formed. IIRC this is not possible with regexes. You need a parser.
With a valid domain, sending an email is the only real way to verify if the address is actually valid. Well formed doesn't mean accepted.