What does HackerNews think of mailcheck?
Reduce misspelled email addresses in your web apps.
At the time I used "mailcheck": https://github.com/mailcheck/mailcheck
There appears to be a more modern implementation here: https://github.com/ZooTools/email-spell-checker
It reduced the amount of badly entered emails more than any other approach I tried.
Otherwise, yeah, most people would be better served by a library that detects domain typos like https://github.com/mailcheck/mailcheck than spending time on regexes.
Like, if the user types "[email protected]", it pops a dialogue asking "Did you mean [email protected]?". But lets them keep what they typed, or do a different fix if needed.
I found some JS called "mailcheck": https://github.com/mailcheck/mailcheck
I assume it's using popularity statistics, edit distance, etc, to come up with suggestions. There are updated clones that use react, vue, etc, instead of jquery.
With a working ecommerce site, this improved the percentage of correct emails more than anything else I tried, and I had tried many things. Because it's a bad situation when you've taken someone's money and have nothing other than a shipping address to contact them if something goes wrong (bad shipping address, out of stock situation, etc).
https://github.com/mailcheck/mailcheck
Fork modified for React: https://github.com/eligolding/react-mailcheck#readme
It is important to tune it a bit based on what you see after installing it to reduce the amount of bad suggestions.
It's a bit old and requires jquery, but it's fairly easy to gut the library and just use the email logic. It even uses your example of "gnail.com" in the README.
https://github.com/mailcheck/mailcheck
If you really need to validate, the only way I know how is to send them an email and click a link to confirm.
https://github.com/mailcheck/mailcheck
I agree with the idea that it's impossible to validate. But, mailcheck takes the approach of seeing if the email is potentially wrong, then prompting the user with what it thinks they meant. It's usually right, but if not, it allows whatever the user wants.
For example, if your user types in "[email protected]", it will suggest "[email protected]".
RFC 822 describes how messages are encoded when email servers talk to each other. It isn't really about email address validation and is not intended to be used to validate a form field on some registration page.
Unless you're writing an MTA or similar piece of infrastructure there is no reason you should be using the RFC grammar. Even if implementation were easy, it probably isn't what you want. For example, the spec permits inline comments but that's a nonsensical thing to have in the middle of an address you typed into an HTML form. Email addresses entered on a web form should be rejected if they contain comments, IMHO.
I think what most developers really want to know is something like: Can this given email address receive messages? Or: Does this given address actually belong to this user? Well, the only way to test that is to send it a message. At best, regex validation might warn you earlier that a given address couldn't possibly work because it's so obviously malformed. But you can't validate your way into getting people to enter their real email address if they don't want to or if they don't know what it is. If your intent is really just to help catch typos and mistakes, you'd be much better off looking to something like mailcheck [0] which will flag common typos like "[email protected]" even if they result in valid looking addresses.
If you really want to do some clientside validation, just keep a basic regex and warn the user if the address doesn't seem right.. Or use MailCheck[1].
0. http://davidcel.is/blog/2012/09/06/stop-validating-email-add...