Live data from Hacker News

The Correct Way to Validate Email Addresses

hackernoon.com

381–390 of 405 posts

Re: The Correct Way to Validate Email Addresses

#381
post #120

At this point, our email validity criteria: .+@.+\..{2,} That is, at least one character for the inbox, at least one character for the domain, at least two for the TLD (we assume that TLD-less domains are undeliverable by us). This ensures we don't allow 'a@a' or 'a@a.a', but do allow 'a@a.io'.

Ian Goldberg once maintained the email address , touted as the shortest possible. An edge case, but it would fail your validation.

Re: The Correct Way to Validate Email Addresses

#382

The number of websites that try reject my email address with a + in it, ugh! Surprisingly, the validation is often done 100% client-side anyway, and simply modifying the incorrect regex lets my email address through... If I wrecked havoc on your back-end, then it's your fault for sucking ;)

I just silently accept your + and throw the insignificant bit away.

Re: The Correct Way to Validate Email Addresses

#383
post #37

Hmm, sorry but I don't buy that the "correct way to validate" is not to validate the input. Email addresses aren't a special enough case to be handled differently than any other user input, which we always validate to both sanitize and show client-side errors, if nothing else. Sure, the complete regex is complex, but it is defined and is hardly unconquerable. Look at Django's `EmailValidator` implementation for examp…

> 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,…

1. Strip non alphanumerics except +

2. Remove everything between + and @

3. Do validation

Re: The Correct Way to Validate Email Addresses

#384

Hmm, sorry but I don't buy that the "correct way to validate" is not to validate the input. Email addresses aren't a special enough case to be handled differently than any other user input, which we always validate to both sanitize and show client-side errors, if nothing else. Sure, the complete regex is complex, but it is defined and is hardly unconquerable. Look at Django's `EmailValidator` implementation for examp…

Regarding that testdata, what is the reason for rejecting bare IP literals on the right hand side? It seems pedantic to require the square braces.

You shouldn't be accepting raw ips for e-mail anyway.

Re: The Correct Way to Validate Email Addresses

#385

Earlier quoted context omitted.

a@[IPv6:2001::1] is, unfortunately for your validation regex, a valid e-mail address. [EDIT: I see that you consider TLD-free e-mail addresses undeliverable; still!]

.+@.+ FTW?

Enjoy getting a billion e-mails per second written to root@localhost

Re: The Correct Way to Validate Email Addresses

#386
post #46
post #26

Earlier quoted context omitted.

Address validation by sending an email should only be used if it is required for some reason to verify the user owns the email account. Otherwise, it's not a great UX.

I honestly can't think of a reason you'd ask a user for their email but not need to validate it. For being able to do password resets later, permission to add to mailing list, avoiding sending private info to the wrong user, avoiding allowing someone to masquerading or impersonate someone they're not.. All should be validated. If you're looking for a username as login identity and nothing more (and you don't have pas…

"For being able to do password resets later" - don't need to validate.

Mailing list - reluctant OK

"avoiding sending private info to the wrong user" - how could this happen?

"avoiding allowing someone to masquerading or impersonate someone they're not" - how could this happen? Like if I signed up as tim@apple.com? What could realistically happen?

Re: The Correct Way to Validate Email Addresses

#389
post #374

Earlier quoted context omitted.

"callable via text"? What does that even mean? The command line is an API, isn't it? If people don't manage to pass an ampersand to another program via the command line, that's really no different than people failing to pass an ampersand as a URI parameter to an HTTP resource: Failure to encode properly. There is absolutely nothing that prevents you from passing an ampersand (or any other characters) to a program via…

> "callable via text"? What does that even mean? It means you have to execute commands through a shell. A real API would be something you could include in your program, execute a method against and get a list of objects back. Instead all these basic command are replicated in every framework. As far as encoding properly, you're preaching to the choir, but out in the real world there is still injection attacks everywhe…

> It means you have to execute commands through a shell.

Except you don't. There is no need to involve a shell.

> A real API would be something you could include in your program, execute a method against and get a list of objects back.

So, Web APIs are not APIs?

Also, you can execute methods against command line programs, method names usually start with a dash.

Re: The Correct Way to Validate Email Addresses

#390

Earlier quoted context omitted.

My bank limits passwords at 15 characters. The best thing? There is no verification, it just cuts off. Have fun figuring out why you can not login anymore.

My bank limits passwords to ten chars. Ten! Have you ever heard any reasoning behind why they do this? The "best" excuse I've heard is so that customers don't forget. As if they don't have a "Forgot password?" link right there .

When I forget my banks password, I have to go to the closest client centre. Ironically, the only time I've had to do that is when my password was truncated.
Post reply on HN