6 ms·
A useful list. I was surprised to find that I'd only heard of one of these. The pattern attribute for regular expressions looks like a great addition. Obligato
by aidos 13y ago
A useful list. I was surprised to find that I'd only heard of one of these.
The pattern attribute for regular expressions looks like a great addition. Obligatory comment that "no more...server side code to check if the user's input is a valid email" is clearly a terrible advice. Always validate on the server.
- ancarda 13y agoI should point out it's generally not a good idea to try to use regex on an email address. It's surprisingly complex and very easy to miss something. I'd rely on type="email" and send a verification link server-side.
- callahad 13y agoWhat out the WHATWG's take on it: http://www.whatwg.org/specs/web-apps/current-work/multipage/states-of-the-type-attribute.html#e-mail-state-%28type=email%29 http://www.whatwg.org/specs/web-apps/current-work/multipage/... Specifically, they've redefined the format of email addresses in a way that's much simpler and is actually amenable to regular expressions. "This requirement is a willful violation of RFC 5322, which defines a syntax for e-mail addresses that is simultaneously too strict (before the "@" character), too vague (after the "@" character), and too lax (allowing comments, whitespace characters, and quoted strings in manners unfamiliar to most users) to be of practical use here." The spec even includes a Perl-compatible regex as an example. :)
- deleted 13y ago[deleted]
- ubernostrum 13y agoYou know, I really think at this point that the random historical crap that's technically legal in an email address should be treated the same as if you walked into a restaurant and tried to order in Latin. It's time to retire a lot of it and tell people to move on.
- daker 13y agoExactly :)
- MrDOS 13y agoThat doesn't change the fact that a lot of validators disallow common, everyday things like + tags or even . characters. The only good way to be sure is to make sure the address contains an @ SOMEWHERE other than the last character (.+@.+, maybe), and then send a validation e-mail.
- daker 13y agoThanks for your suggestion, i agree with you on that, the server side validation is _necessary_ .
- JoeAcchino 13y agoThis regexp [^ @]*@[^ @]* will validate strings like `@example.com` and `joe@` and even a single `@`. Probably [^ @]+@[^ @]+ is what he wants, plus server side validation (that is the classic "click link to validate address" email).
- daker 13y agoThanks for the suggestion, i will check that :)
- Tautologistics 13y agoForgot the SOL/EOL markers; the above will still match a substring, e.g. xxx@xxx@xxx.com. Try: ^[^ @]+@[^ @]+$ That said, HTML5 has something even better if the input is expected to be an email address: input@type=email See http://www.w3.org/TR/html-markup/input.email.html http://www.w3.org/TR/html-markup/input.email.html for more details.
- richbradshaw 13y agoThe good thing is that the regex will be the same. It's also pretty trivial to write a polyfill to work on old browsers. I've found it's really nice to define that in one place then to use it everywhere. Newer users get the HTML5 validation, older ones the Javascript fallback, and everyone gets a second round of checking before it hits the database.
- jammi 13y agoNo, don't validate email addresses with regex. It's more complex than that.
- rimantas 13y agoPattern attribute can also be used to specify what kind of keyboard should your smartphone show when field receives focus, e.g. numeric only.