3 ms·
Email regex: (.*)@(.*) If you need anything more specific the best bet is to try send an email to it.
by Macha 4y ago
Email regex: (.*)@(.*)
If you need anything more specific the best bet is to try send an email to it.
- johannes1234321 4y agoI would filter out at least whitespaces and comma. Aside from catching typos this also protects against header injection or spam abusenby sending to multiple recipients. And yes, those should be defended when constructing the mail, but checking early doesn't cost much.
- gnabgib 4y agoWhite space and comma are allowed in the local part (left of @), as long as it's surrounded by quotes [https://en.wikipedia.org/wiki/Email_address#Local-part https://en.wikipedia.org/wiki/Email_address#Local-part] [https://www.rfc-editor.org/rfc/rfc5322#section-3.2.4 https://www.rfc-editor.org/rfc/rfc5322#section-3.2.4]
- kentonv 4y agoHas anyone ever seen a quoted local part though? Honest question! I'd love to hear the details of any specific case where one has ever been used.
- gorm 4y agoNearly correct. You should also do a DNS lookup on $2 and check if it has either a MX record or an A record before trying to send it.
- hn_throwaway_99 4y agoFWIW the linked library does that, https://github.com/dominicsayers/isemail/blob/master/is_email.php#L167 https://github.com/dominicsayers/isemail/blob/master/is_emai...
- gorm 4y agoIt looks like it only check for a MX, but email could might be delivered with just an A record and without a MX record I think.
- lokedhs 4y agoI do almost exactly that, but I replace the stars with plus. I don't think empty name or domain parts are legal?
- alxmng 4y agoShould be /^[^@]+@[^@]+$/ at least, because you need something before and after @
- etu 4y agoIt's allowed to have @ as part of the local part if it's quoted. So that wouldn't match my email `"foo@bar"@example.org`
- gaws 4y agoBreasts with a chest tattoo.