Live data from Hacker News

Perfect email regex finally found

fightingforalostcause.net

11–20 of 118 posts

Re: Perfect email regex finally found

#11
Nothing is finished, nothing is permanent, and nothing is perfect.

In particular, one of the evaluation tests used here is wrong: it requires failure-to-match on a TLD with a digit in it:

numbersInTLD@domain.c0m

In fact, IDN TLDs will have digits in them. An internet-draft is in the works to replace RFC1123's IDN-unfriendly implication that digits in TLDs are illegal:

http://tools.ietf.org/html/draft-liman-tld-names-02

Re: Perfect email regex finally found

#12
post #2

How ugly do non-regex based email validation functions look? I've never seen one, but I've always wondered if that was a more elegant solution.

One nice looking trick I've seen is checking the domain of the email address for an MX record. (e.g. http://php.dzone.com/news/php-email-validator-email-mx-d ) Possibly this approach is too slow to use by itself without a regex. Also maybe there are other problems with this method I'm not aware of?

MX record is not required. You should allow hosts with only A records too.

http://tools.ietf.org/html/rfc5321#section-5.1

Re: Perfect email regex finally found

#13

Earlier quoted context omitted.

One nice looking trick I've seen is checking the domain of the email address for an MX record. (e.g. http://php.dzone.com/news/php-email-validator-email-mx-d ) Possibly this approach is too slow to use by itself without a regex. Also maybe there are other problems with this method I'm not aware of?

I suggested that a while back but was told that due to spam, you can get lots of false negatives from this technique and others. The best way to validate an email remains to be a test email apparently.

Yeah, that's a really quick way to get IP banned from most email hosts.

Re: Perfect email regex finally found

#14
I've accepted that it's best to treat people like grown-ups and if there's '@' and '.' and it's retyped then it passes. Someone can easily submit a fake name or phone number or street address, and e-mail's no different.

If they get it wrong, intentionally or not, then they don't get their receipt, confirmation, validation link, etc. and I believe in most cases the incentive is there for them to get it right.

In the rare case where there's some incentive to circumvent the system and this has some measurable impact on a site, then more validation may be warranted. Otherwise, why worry about it?

Also: HTML5. ;)

Re: Perfect email regex finally found

#15
post #6

&*=?^+{}'~@12.34.56.78:2000 really looks strange, even though its a valid email. Good luck trying to register on any site with it though :)

What's the deal with using a port number in an e-mail address? I can't imagine many systems supporting that. Anyone got any more info on it that doesn't involve me digging through 101 pages of RFCs? :-)

Re: Perfect email regex finally found

#16
It does not look like any of these can detect or were tested against quoted-local-part addresses. As I understand it, the local part can be quoted to allow illegal characters to be used, e.g. "John Doe"@example.com

I fully understand that these are not in common use, but they are part of the RFC and may be in use somewhere.

Re: Perfect email regex finally found

#17

Earlier quoted context omitted.

One nice looking trick I've seen is checking the domain of the email address for an MX record. (e.g. http://php.dzone.com/news/php-email-validator-email-mx-d ) Possibly this approach is too slow to use by itself without a regex. Also maybe there are other problems with this method I'm not aware of?

I suggested that a while back but was told that due to spam, you can get lots of false negatives from this technique and others. The best way to validate an email remains to be a test email apparently.

You must be thinking of something like this: http://www.webdigi.co.uk/blog/2009/how-to-check-if-an-email-...

Merely looking up MX records is something you do for a _domain_ and it's no different than the DNS requests your computer makes when you go to a website.

Re: Perfect email regex finally found

#19
post #7
post #3

Earlier quoted context omitted.

Regex is the only real sensible way to validate strings until something better is found. Even if you just wrote code to do it manually, you'd really just be writing a verbose and poorly implemented finite state machine that globbed symbols together, which in the end, would just be inferior to writing a well tested Regex string. Regex can be easier to read if you have something do a graphical expansion for you. Otherw…

That's just silly. Depending on what's in the string, writing a parser might be much better than a regex. Lots of parser libraries already out there, too.

I can agree with this sentiment, there's also nothing wrong with writing a parser that breaks the input up into pieces and validates those individual parts using specialized regular expressions.
Post reply on HN