Live data from Hacker News

Email Regex that works 99.99%

emailregex.com

11–20 of 65 posts

Re: Email Regex that works 99.99%

#11
Alternatively, don't validate email addresses with a regex because it's pointless. Check that at least an '@' symbol is present and just send a damn email already[0]. Or better, don't send a damn email at all and let them access it because it's pointless to have an extra verification step.

If you really want to do some clientside validation, just keep a basic regex and warn the user if the address doesn't seem right.. Or use MailCheck[1].

0. http://davidcel.is/blog/2012/09/06/stop-validating-email-add...

1. https://github.com/mailcheck/mailcheck

Re: Email Regex that works 99.99%

#12
post #6

I believe this falls under the category of "things that may be fun to play around with but should never be used in a real system". Unfortunately, I bet there are thousands of "real systems" employing regexes like this... How many problems does this solve? Probably zero. How many does (/will) it cause? Probably much more than zero.

Not sure why this has been downvoted, but yes these sort of things do cause more problems than they solve.

Case in point, at work the other day I found a bug in a service I manage. It consists of a front end form (built by one team), which submits data to another system (built by my team), which then passes the data to a third party. The third party was rejecting the data we were trying to send them as the email addresses were apparently invalid. The validation they were doing didn't match the validation the front end form did, so to the user everything seemed fine.

Re: Email Regex that works 99.99%

#14

I simply don't validate emails up front anymore. The only thing I check for is if the string contains an @-char, I only do that to be nice if it's left out by accident. Instead of having a monstrous regex pattern in my code I simply email a confirmation link the user must confirm.

That's the thing, the only way to validate an email address anyway is to actually have the user take some action to do so. Otherwise, I would question how important setting up the email thing is in the first place.

Re: Email Regex that works 99.99%

#15
Note that these regexes aren't even matching the same thing, so who knows what these things are matching. Whatever it is, it's probably not 99.99% of the world's emails, and either way nobody is going to check that. Especially nobody is going to parse that Perl beast.

As a tangential anecdote, I always thought it would be interesting to drop a backdoor into some canonical piece of code like this that noobs are bound to copy-paste. It might be the most efficient way to worm your way into the largest number of computers worldwide.

Re: Email Regex that works 99.99%

#19
post #5

Utterly pointless. An email regex tells you that the email address (probably) conforms to a pattern that means it might be a valid email address (for now, until new weird TLDs emerge and the patterns have to change...), but it has no way of telling you whether that address can actually receive mail. `foo@bar` fails these regular expressions and `foo@bar.invalid` passes them, but neither will receive mail. As I have t…

Completely useful, as part of a two step process:1 1. Filter with the regex - what's left has a valid format, making step 2 much saner. 2. Extract and validate the domain name - super simple now, because the domain component is known to be sane. (Optional but good idea 3: Handle exceptions....) Step 1 is almost always the hardest part, now it's mostly done.

The assumption here is "0. create a regex that does not have false negatives". You seem to be taking the author's word for the "99.9% Works" part - based on what? (Exactly.)

Re: Email Regex that works 99.99%

#20
In JS the regex is built into the browser: you can leverage HTML5 .checkValidity() on any type="email" input.

https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Form...

Note this is super liberal, so user@domainwithnodots (which is RFC valid, but probably also a user error) is still considered valid.

Post reply on HN