4 ms·
There are basically three levels of address checking: 1) You need to validate an email field for login or a website - checking for an @ mark with some text bef
by raasdnil 5y ago
There are basically three levels of address checking:
1) You need to validate an email field for login or a website - checking for an @ mark with some text before and at least one . after the @ will do for this.
2) You need to do some sort of address validation, library regexps like this will do for 99.9...% of these.
3) You are building an email handling system which needs to actually support the RFCs, in which case regexp will not handle what you need, and you need to use a proper parser, like https://github.com/mikel/mail/tree/master/lib/mail/parsers https://github.com/mikel/mail/tree/master/lib/mail/parsers
Ref: I am the original author of the Ruby mail gem.
- vb6sp6 5y ago
- AdamJacobMuller 5y ago> at least one . after the @ will do for this technically not required... [adam@solomon]$ dig +noall +answer mx ai ai. 21572 IN MX 10 mail.offshore.ai.
- teruakohatu 5y agoAs soon as I read the OP's comment I knew someone would reply to say the dot was not technically required, but I didn't expect to see an actual publicly addressable example!
- AdamJacobMuller 5y agoI actually searched and was surprised no one beat me to it.
- zamalek 5y agoI've read this more than once, and it basically always boils down to: "The only way to verify an email address is to send an email to it." In my opinion, the optimal validation is soft validation: "your email address doesn't look right, continue with it?"
- throw0101a 5y ago> In my opinion, the optimal validation is soft validation: "your email address doesn't look right, continue with it?" And then hope the server's e-mail workflow can handle subaddressing because you entered in something like "username+service@gmail.com". Seems like a lot of folks don't like '+', even though it's been part of the e-mail system since the 1980s.
- raasdnil 5y agook, impressed. Happily the mail gem will see that as a valid address :)
- cpcallen 5y agoYep. Back in university I was acquainted with the fellow who set up the MX record for .ai (and assigned himself the memorable address n@ai). IIRC he was involved in planning an academic conference to be held there.
- throw0101a 5y agoFor the record, it is owned by Anguilla (in the Caribbean): * https://en.wikipedia.org/wiki/.ai https://en.wikipedia.org/wiki/.ai
- AdamJacobMuller 5y agoYeah I met him once. I didn't want to call him out on it :)
- nicoburns 5y agoLevel 4: You need an address backed by an actually valid mailbox. At which point you need to send an email to the address to validate.
- hamandcheese 5y agoAt which point, why even bother with 1, 2, and 3? Just try to send it.
- nicoburns 5y agoWell it’s usually worth doing 1. It’s super easy, and it catches silly typos (like people putting their name instead of their email address or something)
- pmarreck 5y agoHeh. A while back I worked at <now bought-out startup> whose main business included handling emails, and they were looking to speed it up, so I came up with this code to do the header parsing, which was 250x faster than the mail gem... but they ended up not going with it due to risk >..< https://gist.github.com/pmarreck/8476538 https://gist.github.com/pmarreck/8476538
- eyelidlessness 5y agoYou can certainly do it with regex, given a certainly non-regular regex implementation and a probably unbounded computational space. But you shouldn’t. Ref: I (regrettably) have one of the top SO answers for matching URLs. It’s wrong in a few different ways and I’ve stopped fielding edits/comments for the last few years.
- Fire-Dragon-DoL 5y agoThank you. Your gem helped me multiple times throughout the years and helped me dealing with some hard problems