5 ms·
Sometimes it's best just not to bother with a regular expression. Email addresses are a prime example of where this is true.
by constant_change 15y ago
Sometimes it's best just not to bother with a regular expression. Email addresses are a prime example of where this is true.
- gmac 15y agoThis has been discussed to death all over the place, but I think the take home is not to be too clever rather than not to use regexes. I tend to look for 'something at something dot something': .+@.+\..+ I believe this allows all valid addresses (as well as lots of invalid ones, obviously). But I'm sure someone will let us know if not. :)
- mquander 15y agoObvious counterexample: me@localhost. (Not that this is a useful counterexample in the context of a form submission.)
- ifzen 15y agoIf you REALLY need to validate en email address: http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html but again, only if you REALLY, REALLY , REALLY want to.
- pspeter3 15y agoThat's ridiculous and awesome. I'm glad regular expressions exist so we can make garbage/magic like that
- pavel_lishin 15y agoFor a second, I thought it was a perl script.
- lpolovets 15y agohttp://fightingforalostcause.net/misc/2006/compare-email-regex.php http://fightingforalostcause.net/misc/2006/compare-email-reg... is a good site that has a number of email regex variants and how well they do on various email address formats.