Live data from Hacker News

Ruby's Email Address Regexp

github.com

51–60 of 69 posts

Re: Ruby's Email Address Regexp

#51
post #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 no…

Recently I had a doctors office call me to confirm an appointment instead of obeying my wishes to be contacted via email. The email I provided to their contact form was @. The receptionist was convinced the provided email was incorrect because it was "their" email. I'm not sure what I expected.

Re: Ruby's Email Address Regexp

#52

See also this comparison of email regular expressions (as found in various languages and libraries), compared against a selection of valid email addresses: https://fightingforalostcause.net/content/misc/2006/compare-...

Aren't all me.com addresses now icloud.com addresses as well? Couldn't you just tell them the other one?

Re: Ruby's Email Address Regexp

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

Because it also valudates Cyrillic, Hebrew, Arabic and Chinese e-mail addresses.

Re: Ruby's Email Address Regexp

#54

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…

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

Re: Ruby's Email Address Regexp

#55
post #12

Earlier quoted context omitted.

While that's true, `@@.@` fulfils "an @ symbol with something before it, and something after it".

The original comment probably meant something like this: ^[^@] @[^@] $

That's only one letter before and after.

Re: Ruby's Email Address Regexp

#56
post #51
post #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 no…

Recently I had a doctors office call me to confirm an appointment instead of obeying my wishes to be contacted via email. The email I provided to their contact form was @ . The receptionist was convinced the provided email was incorrect because it was "their" email. I'm not sure what I expected.

I've done this for decades so I could see who was selling my email address and spamming me, and the answer is: nobody. That's not where spam comes from apparently. I still do it out of habit though.

Re: Ruby's Email Address Regexp

#57
post #36

Earlier quoted context omitted.

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.

This is actually an uncommon example of an off-by-two error as they used strictly greater than 2.

  a@domain   fail
  ab@domain  fail
  abc@domain ok

Re: Ruby's Email Address Regexp

#58

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.

ok, impressed. Happily the mail gem will see that as a valid address :)

Re: Ruby's Email Address Regexp

#59

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.

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

Re: Ruby's Email Address Regexp

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

Heh, I actually meant `>=`. But as others have pointed out, that still excludes 2 letter users. Really it should be `>= 0`.
Post reply on HN