Live data from Hacker News

The Correct Way to Validate Email Addresses

hackernoon.com

121–130 of 405 posts

Re: The Correct Way to Validate Email Addresses

#123
post #37

Earlier quoted context omitted.

> Sure, the complete regex is complex, but it is defined and is hardly unconquerable. If it is a regular expression, then it is not able to match all valid email addresses, because the grammar of email addresses is context-free, and regular expressions can only match regular grammars. It doesn't matter if it is defined or not: if it's a true regular expression, then it simply cannot validate email addresses. (it may,…

> ...@(valid)example.org(honest) Are those parens really permitted in the host name? I'm looking at RFC 3696. > 3. Restrictions on email addresses > .... The syntax of the domain part corresponds to that in the previous section. and > 2. Restrictions on domain (DNS) names > Any characters, or combination of bits (as octets), are permitted in DNS names. However, there is a preferred form that is required by most appli…

> > ...@(valid)example.org(honest)

> Are those parens really permitted in the host name? I'm looking at RFC 3696.

RFC5322 states that an addr-spec consists of a local-part, followed by @, followed by a domain. It states that a domain may be a domain-literal; a domain-literal may begin and end with commented folding whitespace (CFWS). It's all in https://tools.ietf.org/html/rfc5322#section-3.4.1

It's only the dtext portion of the domain-literal which must consist of printable ASCII characters, not including [, ] or \.

Yes, foo@bar!baz!quux is a valid RFC5322 email address (decimal 33, i.e. !) is allowed, per the dtext production of the spec) — and so is foo@(comment (nested comment (escaped \(comment)))bar!baz!quux(another (comment (to prove) the point))

Whether one should ever actually use such an address is, of course, another matter entirely.

Re: The Correct Way to Validate Email Addresses

#124

This is the best comprehensive way that I've found: https://github.com/kdisneur/email_checker It breaks down into 3 parts that can be used either independently or as a whole: format, MX and SMTP.

That's just broken, the DNS lookups are wrong, the SMTP implementation is defective, I didn't look any further.

How so? If you could correct it how would you feel about the approach?

Re: The Correct Way to Validate Email Addresses

#125
post #67

Earlier quoted context omitted.

Worse than that: I've encountered a few web sites which accept email addresses with '+' characters... and then tell me that my email address has a ' ' character in it. Every time I see this I think "there's got to be a multiple-form-decoding vulnerability here"...

I've got an account where they just plain stripped the + character. Since I happen to have used only alphanumeric charters after, I am now registered with an email address I can't actually receive mail on - it goes to somebody else's inbox. Account synchronization was involved - IIRC the initial address confirmation message got thorough.

Southwest (Airlines) does this... or did a few years ago.

Re: The Correct Way to Validate Email Addresses

#128

Earlier quoted context omitted.

> combined characters like ´e (can't type the correct e with accent mark) You mean é ? :-)

Yes. OS X keyboard drives me nuts sometimes, Karabiner can only fix some bits of the weirdness.

It's worth playing around with the option key when pressing letters on OS X. You're able to enter a ton of common (western) characters with that alone, without ever opening the "special characters" (ugh) palette.

Also the default configuration for a couple versions now (which I hate, but I know it benefits others) is if you hold a commonly (western) accented character, it'll suggest accents for it.

Re: The Correct Way to Validate Email Addresses

#129

I do a lot of optin email. Here are some examples of bounced emails that people use to sign up: * somename@gmail.co * anothername@yhoo.com * myemail@hotmial.com These are very common errors that occur nearly every day. A regex isn't going to help here. What does help, is a notification that asks people to verify what they typed –– if the email contains an obvious, common error, such as one listed above.

But I want a hot mial!

Re: The Correct Way to Validate Email Addresses

#130
post #48

Earlier quoted context omitted.

Even worse is rejecting my password because it has a + in it! Why do you as a business care what my random password generator spit out?? Scarier still is when it's a server-side response that rejects my password for its contents...

Or when a password that is generated by my password manager is rejected with a message "Password should be 12 characters maximum". Why???

Even 15, 16, 31, or 32 (all of which I've seen before) would make more sense. 12 is "odd".
Post reply on HN