Live data from Hacker News

Ruby's Email Address Regexp

github.com

41–50 of 69 posts

Re: Ruby's Email Address Regexp

#41

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…

> 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.

As 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!

Re: Ruby's Email Address Regexp

#42

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…

> 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.

I'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?"

Re: Ruby's Email Address Regexp

#43

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…

Level 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.

At which point, why even bother with 1, 2, and 3? Just try to send it.

Re: Ruby's Email Address Regexp

#44
post #36
post #6

Earlier quoted context omitted.

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!

Why 2? Greater than 0, sure.

The index of the first character is 0 and an email must have a local part so that means the index of "@" has to be at least 1. My guess is OP also forgot the index of the first character is 0 instead of 1 resulting in 1+1=2 (that or they meant >=).

Off by one errors are about half of working with arrays.

Re: Ruby's Email Address Regexp

#45

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.

Yes, although that only helps if they typo the address to one that doesn’t happen to exist. Quite likely to hit a valid one by mistake with the size of gmails user base. I know at least one person who uses my emails address by mistake.

Re: Ruby's Email Address Regexp

#46

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…

Heh. A while back I worked at 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

Re: Ruby's Email Address Regexp

#49

Earlier quoted context omitted.

Level 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.

At which point, why even bother with 1, 2, and 3? Just try to send it.

Well 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)

Re: Ruby's Email Address Regexp

#50
post #47

I have a .email domain that at least one major site rejects as invalid. Quite annoying.

Right. Discover bank app's zelle settings don't allow any email.on .in domain, as in they assume that nobody from India, who already has an email on .in domain, will come to US & use their zelle.
Post reply on HN