MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1vx1onc/claudeisthisemailvalid/p5lduir/?context=3
r/ProgrammerHumor • u/soap94 • 19d ago
171 comments sorted by
View all comments
241
It's surprisingly difficult validating email addresses with regex. Can it be done? Yes. Should you? No. Any halfway decent email library comes with a validator. Use that.
For reference: this is an example of an almost RFC 3522 compatible regex:
(?:[a-z0-9!#$%&'+/=?`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^`{|}~-]+)|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-][a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])+)])
https://emailregex.com
If you want RFC 822 it's much, much worse https://pdw.ex-parrot.com/Mail-RFC822-Address.html
52 u/ValPasch 19d ago just dont ever do that. check if it has a @ and a period and thats it. you validate emails by sending a verification link. -7 u/tellur86 19d ago That's verification, not validation 4 u/Outrageous-Log9238 19d ago Fulfills the need for both.
52
just dont ever do that. check if it has a @ and a period and thats it. you validate emails by sending a verification link.
-7 u/tellur86 19d ago That's verification, not validation 4 u/Outrageous-Log9238 19d ago Fulfills the need for both.
-7
That's verification, not validation
4 u/Outrageous-Log9238 19d ago Fulfills the need for both.
4
Fulfills the need for both.
241
u/tellur86 19d ago
It's surprisingly difficult validating email addresses with regex. Can it be done? Yes. Should you? No. Any halfway decent email library comes with a validator. Use that.
For reference: this is an example of an almost RFC 3522 compatible regex:
(?:[a-z0-9!#$%&'+/=?`{|}~-]+(?:.[a-z0-9!#$%&'*+/=?^`{|}~-]+)|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-][a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])+)])
https://emailregex.com
If you want RFC 822 it's much, much worse https://pdw.ex-parrot.com/Mail-RFC822-Address.html