Live data from Hacker News

Ruby's Email Address Regexp

github.com

21–30 of 69 posts

Re: Ruby's Email Address Regexp

#21
The most helpful thing I've used in the real world is something that looks for common typographical errors, even if the email is technically valid.

Like, if the user types "john.doe@gnail.com", it pops a dialogue asking "Did you mean john.doe@gmail.com?". 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).

Re: Ruby's Email Address Regexp

#23
post #15

The one from Perl's Email::Valid is significantly harder on the eyes: https://metacpan.org/dist/Email-Valid/source/lib/Email/Valid... Edit: Email::Valid is fairly well respected for getting the rules right...

Classic Perl. Those were the days.

Re: Ruby's Email Address Regexp

#24
This regexp and the whatwg one it is based off (correctly) do not validate the presence of a TLD since it's not technically required (foo@bar is considered valid). But if you are building consumer products it's best to test that there is at least a presence of something TLD-like after validating against this regexp.

Re: Ruby's Email Address Regexp

#26
SMTP had a very useful VRFY command after you've tested for the @ and MX record, but only a handful of service providers will tell you if the email is invalid nowadays due to spam concerns.

Gmail still does though, which is a big deal as 90% of people who register on my sites are using a gmail address only and thus easy to verify instantly and notify the user to double check the email spelling.

Re: Ruby's Email Address Regexp

#27
I have yet to find the library that is doing this, but I have had a number of issues with website really not liking an "@me.com" email address.

I assume there is some commonly used library (or multiple) out there that don't recognize an email a domain that is less than 3?

But it is driving me insane, most recently I was on the phone with my vet and she told me their system told them my email was invalid (and would not accept it).

Re: Ruby's Email Address Regexp

#28
post #13

Earlier quoted context omitted.

The regex listed there isn’t that much more complex. It’s basically a check for *@a*.* where * is some minimal whitelist of valid characters and a is an alphanumeric to start the domain name.

And even though that sounds reasonable, it is still wrong. Technically, you do not even need the dot, if you add an MX record to a whole TLD or have some other funky DNS setup. Source: https://www.netmeister.org/blog/email.html

The linked regexp doesn't require the TLD: https://rubular.com/r/Y9G4HR2Ox8gzqd

Re: Ruby's Email Address Regexp

#30
post #6
post #3

The best email regex just checks for an @ symbol with something before it, and something after it. Anything more complex is a waste of time.

Never mind the regex, `email.indexOf("@") > 2` does the trick and faster if you happen to need to check many emails. All websites these days require verification of emails (regardless of whether or not it's necessary), and if that's not enough validation, I don't know what is!

I would use `email.includes('@')`, it only needs to be polyfilled for IE since it's in every modern browser JS engine.
Post reply on HN