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 r…
Along those lines, I've settled on the following overly permissive regex: /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/ -- it makes sure it looks something like an email address (a@b.cd)
Perfect email regex finally found
41–50 of 118 posts
Re: Perfect email regex finally found
#42I'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 r…
Retyped!? Grown-ups can read what they write. Retyping only makes sense for password field, which is obfuscated and doesn't allow copy&paste.
Multiply that by say, 130,000 people, and you are dealing with 325 people who don't receive their download, etc. and are not happy!
I think what would be really awesome is a regex that catches these common typos and warns the user immediately.
Re: Perfect email regex finally found
#43Earlier quoted context omitted.
Retyped!? Grown-ups can read what they write. Retyping only makes sense for password field, which is obfuscated and doesn't allow copy&paste.
I would estimate about 0.25% of people will make a typo like "@homail.com" or "@gmial.com" Multiply that by say, 130,000 people, and you are dealing with 325 people who don't receive their download, etc. and are not happy! I think what would be really awesome is a regex that catches these common typos and warns the user immediately.
Re: Perfect email regex finally found
#44I'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 r…
Oh, and don't forget to make sure that one component in your spam^W email processing chain correctly encodes unicode charaters in the domain part into punycode.
Re: Perfect email regex finally found
#45Re: Perfect email regex finally found
#46How 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…
There are plenty of ‘better’ (in the sense of ‘more powerful’) string-validation techniques. For example, lots of grammars are expressed in BNF; the languages that can be so expressed are (if I remember my Chomsky hierarchy correctly) the context-free grammars, a strictly larger class than the regular languages. The extra power comes from the fact that they have the expressive power of a finite-state automaton augmented by an (infinite) stack. (It's fair to argue that it's not ‘really’ infinite, since a computer's memory is finite; but, in that sense, real-life computers will never be Turing complete.)
(Of course, common ‘regular-expression’ libraries aren't actually regular any more, because of added features like capture groups. I don't know if they recognise all CFG's, though; I suspect not.)
Given this, why would we use regular expressions? Well, by intentionally sacrificing power, we can achieve faster matching (http://swtch.com/~rsc/regexp/regexp1.html) and, probably, lower memory usage. Sometimes this trade-off is worth it, even if it means that the match must be somewhat fuzzy; but sometimes one needs a precise match, and regexes just aren't up to the job.
Re: Perfect email regex finally found
#47This one in perl is fun as well: http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html
Re: Perfect email regex finally found
#48It's 6,598 bytes long.
Re: Perfect email regex finally found
#49I'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 r…
My thoughts exactly. There are so many websites that tell me my valid email address is invalid that it's not even funny. These people then have to deal with phonecalls and lost business, because their form won't even submit without a valid email address (and why should I change if they're the ones that suck). BTW, the email address that doesn't work is "jon-whatever@jrock.us". The .us confuses people and the - confus…