Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It was posted a fews days ago in this thread http://news.ycombinator.com/item?id=4774426 with a great comment:

> If seeing this doesn't make you second guess using a RegExp when a parser is more appropriate, well...you might be a Perl programmer?



I am one. The regexp performs better than the parser, and works in my existing perl code, and has a lot of visibility now, so it's a no brainer for me to use it.


i'm building a simple offline webapp for collecting email addresses at an event on an ipad with no internet connection.

im using a simple regex (may use this one instead) to validate email before sticking in localStorage for latter retrial... if not with regex, how should i validate the email addresses?


As somebody else said, don't.

If you really feel you need some kind of validation, have two email fields so the user can enter it twice and double check it themselves. No matter how much effort you put into it, and how complicated your validation code is, if the users want to mess with you, they can always just enter a valid fake address, so there's no point wasting a lot of energy on it because it's easy to defeat anyway.

And since it's impossible to validate addresses with a regular expression, there's a small chance you'll reject a valid address and look dumb.


I see the two fields thing a lot. It's pointless since I can copy and paste into the second field. Unless they use JavaScript to disable pasting, which is obnoxious.


I'd wager that being likely to mistype one's own e-mail address correlates highly with not realizing you can copy/paste between the fields.


What do you expect to achieve by validating the address at all?


ask the user to check what they entered and try again


A parser would likely be shorter and easier to understand.


They hint that they use this huge regex instead of a parser for performance reasons. At any rate, the regex was not written by hand; it is a concatenation of simpler, easier to understand regexes.


> " collecting email addresses at an event on an ipad with no internet connection."

Parsers require an internet connection to work now?


He's preempting the "the only way to validate email is to send them an email" responses.


don't


Why not save everything they enter and then validate later. I'd rather get bad email addresses while letting everything in than lose valid email addresses but block bad input.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: