News for hackers. Stuff that matters.
Re:HTML5 Features you need to know by aidos on Saturday May 25, 2013 @04:12PM (#5768666)
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.

Re:HTML5 Features you need to know by ancarda on Saturday May 25, 2013 @04:14PM (#5768669)
I 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.
Re:HTML5 Features you need to know by callahad on Saturday May 25, 2013 @04:34PM (#5768714)
What out the WHATWG's take on it: 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. :)

Re:HTML5 Features you need to know by callahad on Saturday May 25, 2013 @11:13PM (#5769873)
s/What out/Check out/ # How the hell did I miss that typo? :(
Re:HTML5 Features you need to know by julien_c on Monday May 27, 2013 @04:53AM (#5773951)
You can edit your comments on HN, right?
Re:HTML5 Features you need to know by barrkel on Monday May 27, 2013 @04:22PM (#5776409)
Not after an hour.
Re:HTML5 Features you need to know by ubernostrum on Sunday May 26, 2013 @02:01AM (#5770210)
You 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.
Re:HTML5 Features you need to know by MrDOS on Monday May 27, 2013 @10:06AM (#5774680)
That 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.
Re:HTML5 Features you need to know by JoeAcchino on Saturday May 25, 2013 @05:25PM (#5768913)
This 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).
Re:HTML5 Features you need to know by Tautologistics on Sunday May 26, 2013 @02:29PM (#5771956)
Forgot the SOL/EOL markers; the above will still match a substring, e.g. xxx@[email protected]. 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 for more details.

Re:HTML5 Features you need to know by daker on Saturday May 25, 2013 @06:26PM (#5769092)
Thanks for the suggestion, i will check that :)
Re:HTML5 Features you need to know by richbradshaw on Sunday May 26, 2013 @06:18AM (#5770703)
The 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.
Re:HTML5 Features you need to know by jammi on Sunday May 26, 2013 @11:48AM (#5771378)
No, don't validate email addresses with regex. It's more complex than that.
Re:HTML5 Features you need to know by rimantas on Sunday May 26, 2013 @01:21PM (#5771691)
Pattern attribute can also be used to specify what kind of keyboard should your smartphone show when field receives focus, e.g. numeric only.
Re:HTML5 Features you need to know by daker on Saturday May 25, 2013 @04:39PM (#5768741)
Thanks for your suggestion, i agree with you on that, the server side validation is _necessary_ .