Live data from Hacker News

Perfect email regex finally found

fightingforalostcause.net

1–10 of 118 posts

Re: Perfect email regex finally found

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

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. Otherwise, it's write-once, read-never.

Re: Perfect email regex finally found

#5
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?

Re: Perfect email regex finally found

#7
post #3
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.

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.

Re: Perfect email regex finally found

#9
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?

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.

Re: Perfect email regex finally found

#10
post #3
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.

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…

[deleted]
Post reply on HN