SlideShare ist ein Scribd-Unternehmen logo
1 von 41
Downloaden Sie, um offline zu lesen
Validating Forms
(AND MORE)
WITH THE

HTML5 Pattern
Attribute

@cliener
HTML5 RECAP

http://wufoo.com/html5/
Before I get stuck into patterns, I’ll quickly go through some of the important parts of HTML5 forms. If you want to play along at
home, have a look at Wufoo’s HTML Forms guide.
HTML5 RECAP
<input	
  type="email">

Most of the new input types come with awesome custom keyboards for iOS and more recent Android (amongst others). Some
browser versions offer basic validation in but inconsistent implementations mean they can’t be relied upon.
The key new inputs types are “email”,
HTML5 RECAP
<input	
  type="tel">

“tel”,
HTML5 RECAP
<input	
  type="url">

“url” and
HTML5 RECAP
<input	
  type="number">

“number”.
HTML5 RECAP
<input	
  type="datetime">

Unfortunately “datetime”, “time” and “year” input types have been marked as “in danger” by the W3C due to poor and
inconsistent browser support. There’s something of a chicken and egg situation when it comes to standards and browser
support. Unfortunately for the HTML5 date and time inputs,
the chicken looks something like this.
HTML5 RECAP
<input	
  required>

Important attributes to note are “required”,
HTML5 RECAP
<input	
  placeholder=
	
  	
  	
  	
  	
  	
  	
  "dd/mm/yyyy">

“placeholder”
PATTERNS
<input	
  pattern="/d*">

and, of course, “pattern”. Patterns allow you to provide a regular expression string primarily for input validation. A numeric
regulation expression like the this one can trigger a numeric keyboard. You’ll often see the above pattern as “[0-9]*” because
most people don’t know how to write regular expressions to save themselves.
NOW YOU HAVE TWO PROBLEMS

http://evolt.org/node/36435
I can’t remember the origin so I’ll call it an old saying: “You have a problem which can be solved with a regular expression. Now
you have two problems.”
I won’t pretend regular expressions are the easiest to write however a good guide the one on Evolt will certainly make life easier
for you.
PATTERNS
/d*/
.test("12345");
>>>	
  true

I find the JS console (in a browser near you) are a handy way to test out regular expressions. This one matches any numeric value
PATTERNS
/d*/
.test("Once	
  I	
  caught	
  a
	
  	
  	
  	
  	
  	
  	
  fish	
  alive");
>>>	
  false

And correctly returns false to a string.
POSTCODE
/d{4}/
.test("605");
>>>	
  false

Australian postcodes are easily matched with this pattern - exactly four digits - returning false here for “605”
POSTCODE
/d{4}/
.test("6050");
>>>	
  true

and true here for a correct value.
YEAR
/d{4}|d{2}/
.test("13");
>>>	
  true

Getting slightly more complex with a pipe which acts as an “or” switch, we can match either two or four digit years.
TIME
/(([0-­‐1]d)|(2[0-­‐3]))
:[0-­‐5]d/
.test("08:37");
>>>	
  true

Square brackets specify a range of values, round brackets group sub-expressions together: here matching a twenty hour time
value.
TIME
/(([0-­‐1]?d)|(2[0-­‐3]))
(:|.)[0-­‐5]d/
.test("8.37");
>>>	
  true

With a slight modification, we’re now matching a wider range of natural inputs.
DATE
/d{2}/d{2}/d{4}/
.test("24/10/2013");
>>>	
  true

Dates seem fairly straight-forward
DATE
/d{2}/d{2}/d{4}/
.test("99/99/9999");
>>>	
  true

but are a lot more complex than they seem.
DATE
/(?=d)(?:(?:31(?!.(?:0?[2469]|11))|(?:
30|29)(?!.0?2)|29(?=.0?2.(?:(?:(?:1[6-­‐9]|
[2-­‐9]d)?(?:0[48]|[2468][048]|[13579]
[26])|(?:(?:16|[2468][048]|[3579]
[26])00)))(?:x20|$))|(?:2[0-­‐8]|1d|0?
[1-­‐9]))([-­‐/])(?:1[012]|0?[1-­‐9])1(?:
1[6-­‐9]|[2-­‐9]d)?dd(?:(?=x20d)x20|
$))?/
.test("99/99/9999");
>>>	
  false
A bit more work and we end up with this.
At this point I can understand if you’re a little shocked, so I’ll pull it back a little.
EMAIL
/w+@w+.w+/
.test("a@b.c")
>>>	
  true

Email addresses are often something of a mine field but, on the surface, the pattern is fairly simple: “a@b.c”
EMAIL
/w+@w+.w+/
.test("cli+ner@
	
  	
  	
  	
  	
  	
  	
  	
  	
  server.com.au");
>>>	
  true

Already we’re matching better than most email validation rules out there.
EMAIL
/w+@w+.w+/
.test("1337@server.com");
>>>	
  true

Except the simplicity soon gets us unstuck when we get false positives. Given how scary date validation was, it’s tempting to see
what Google has to offer
EMAIL
/(?:(?:rn)?[	
  t])*(?:(?:(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[	
  t]))*"(?:(?:rn)?[	
  t])*)
(?:.(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[	
  t]))*"(?:(?:rn)?
[	
  t])*))*@(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*)(?:.(?:(?:r
n)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*))*|(?:[^()<>@,;:".[]	
  000-­‐
031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[	
  t]))*"(?:(?:rn)?[	
  t])*)*<(?:(?:rn)?[	
  t])*(?:@(?:[^()<>@,;:".[]	
  000-­‐
031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*)(?:.(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:r
n)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*))*(?:,@(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?
=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*)(?:.(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".
[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*))*)*:(?:(?:rn)?[	
  t])*)?(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r
]|.|(?:(?:rn)?[	
  t]))*"(?:(?:rn)?[	
  t])*)(?:.(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r
]|.|(?:(?:rn)?[	
  t]))*"(?:(?:rn)?[	
  t])*))*@(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|
.)*](?:(?:rn)?[	
  t])*)(?:.(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?
[	
  t])*))*>(?:(?:rn)?[	
  t])*)|(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[	
  t]))*"(?:(?:rn)?
[	
  t])*)*:(?:(?:rn)?[	
  t])*(?:(?:(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[	
  t]))*"(?:(?:r
n)?[	
  t])*)(?:.(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[	
  t]))*"(?:(?:r
n)?[	
  t])*))*@(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*)(?:.(?:
(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*))*|(?:[^()<>@,;:".[]	
  
000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[	
  t]))*"(?:(?:rn)?[	
  t])*)*<(?:(?:rn)?[	
  t])*(?:@(?:[^()<>@,;:".[]	
  
000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*)(?:.(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:
(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*))*(?:,@(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|
Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*)(?:.(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:
".[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*))*)*:(?:(?:rn)?[	
  t])*)?(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^
"r]|.|(?:(?:rn)?[	
  t]))*"(?:(?:rn)?[	
  t])*)(?:.(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^
"r]|.|(?:(?:rn)?[	
  t]))*"(?:(?:rn)?[	
  t])*))*@(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]
r]|.)*](?:(?:rn)?[	
  t])*)(?:.(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:
rn)?[	
  t])*))*>(?:(?:rn)?[	
  t])*)(?:,s*(?:(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?
[	
  t]))*"(?:(?:rn)?[	
  t])*)(?:.(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?
[	
  t]))*"(?:(?:rn)?[	
  t])*))*@(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?
[	
  t])*)(?:.(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*))*|(?:
[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[	
  t]))*"(?:(?:rn)?[	
  t])*)*<(?:(?:rn)?[	
  t])*(?:@(?:
[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*)(?:.(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  
000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*))*(?:,@(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:
(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*)(?:.(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|
Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*))*)*:(?:(?:rn)?[	
  t])*)?(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[
["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[	
  t]))*"(?:(?:rn)?[	
  t])*)(?:.(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[
["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[	
  t]))*"(?:(?:rn)?[	
  t])*))*@(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[
["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*)(?:.(?:(?:rn)?[	
  t])*(?:[^()<>@,;:".[]	
  000-­‐031]+(?:(?:(?:rn)?[	
  t])+|Z|(?=[["()<>@,;:".
[]]))|[([^[]r]|.)*](?:(?:rn)?[	
  t])*))*>(?:(?:rn)?[	
  t])*))*)?;s*)/
.test("ha@ha.ha");
>>>	
  true

http://www.codinghorror.com/blog/2005/02/regex-use-vs-regex-abuse.html
And here is 6.2KB of RFC standard-compliant email regular expression.
Which brings me to a major problem when regular expressions.
Unfortunately, a fair number of programmers out in the wild haven’t quite worked out regular expressions yet so you need to be
really careful about what you’re write.
EMAIL
/([w!#%&$'*+-­‐=?^_`{|}~]+[w!#
%&$'*+-­‐=?^_`{|}~.]+[w!#%&$'*+
-­‐=?^_`{|}~]+|[w!#%&$'*+-­‐=?
^_`{|}~]{1,2})@([A-­‐Za-­‐z0-­‐9-­‐]+.)
+[A-­‐Za-­‐z0-­‐9-­‐]+/
.test("1337@server.com");
>>>	
  false
For the record, here’s my RFC-compliant email regular expression.
SECURITY

As a whole, password validation is awful.
SECURITY

Over-validation is a great way to make people hate you
SECURITY

because, as much as you might think otherwise, you don’t know as much about them as you think you do.
SECURITY

But then there are people like, presumably, Bob.
And here be dragyns. In the last couple of years, millions of passwords - hashed and otherwise - have been grabbed from
various online services which means that everything we though we knew about password validation is, in essence, wrong. This
also means that enforced password validation is probably wrong too. So, please don’t. Invest your energy into two factor
authentication or something else that’s actually secure rather than incurring the wrath of the users who do know what they’re
doing.
CREDIT CARDS
"4123	
  5678	
  9012	
  3456"
.replace(/(s)/g,	
  "");
>>>	
  "4123567890123456"

While I’ve shown how awesome regular expressions are for pattern validation, they can also manipulate data. Right here is
everything you need to strip spaces from a credit card number so I can enter it with spaces as it is on my card. You no longer
have any excuses.
ERROR MESSAGES
<input	
  pattern="d{4}"	
  
title="Please	
  enter	
  a	
  
valid	
  postcode	
  e.g.	
  
3000">

Rather crucial when doing pattern validation is presenting a meaningful error message to users. In HTML5, browsers are abusing
the title attribute to this end. You can also set the .setCustomValidity() DOM property but title will work for most instances.
ERROR MESSAGES

The results aren’t perfect, but they’re a whole lot better than server validation.
In summary, are regular expressions better than kittens? I think the answer is definitively yes.
@cliener
http://www.slideshare.net/cliener/
FURTHER READING
HTML5 Rocks: Constraint Validation: Native Client
Side Validation for Web Forms
http://www.html5rocks.com/en/tutorials/
forms/constraintvalidation/

Weitere ähnliche Inhalte

Ähnlich wie Validating forms (and more) with the HTML5 pattern attribute

GCSECS-DefensiveDesign.pptx
GCSECS-DefensiveDesign.pptxGCSECS-DefensiveDesign.pptx
GCSECS-DefensiveDesign.pptxazida3
 
Web Forms People Don't Hate
Web Forms People Don't HateWeb Forms People Don't Hate
Web Forms People Don't Hatecliener
 
The vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQLThe vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQLLukas Eder
 
Como NÃO testar o seu projeto de Software. DevDay 2014
Como NÃO testar o seu projeto de Software. DevDay 2014Como NÃO testar o seu projeto de Software. DevDay 2014
Como NÃO testar o seu projeto de Software. DevDay 2014alexandre freire
 
Basic testing with selenium
Basic testing with seleniumBasic testing with selenium
Basic testing with seleniumSøren Lund
 
Manage Your Data In A B-Boy Stance
Manage Your Data In A B-Boy StanceManage Your Data In A B-Boy Stance
Manage Your Data In A B-Boy StanceJohn Anderson
 
Mountebank and you
Mountebank and youMountebank and you
Mountebank and youVodqaBLR
 
Advanced SQL Injection
Advanced SQL InjectionAdvanced SQL Injection
Advanced SQL Injectionamiable_indian
 
Sql Injection Adv Owasp
Sql Injection Adv OwaspSql Injection Adv Owasp
Sql Injection Adv OwaspAung Khant
 
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and BeyondWebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyondmguillem
 
What you need to know bout html5
What you need to know bout html5What you need to know bout html5
What you need to know bout html5Kevin DeRudder
 
Web Security Mistakes: Trusting The Client
Web Security Mistakes: Trusting The ClientWeb Security Mistakes: Trusting The Client
Web Security Mistakes: Trusting The Clientgrutz
 
Data validation in web applications
Data validation in web applicationsData validation in web applications
Data validation in web applicationssrkirkland
 
Your Tests Are Not Your Specs
Your Tests Are Not Your SpecsYour Tests Are Not Your Specs
Your Tests Are Not Your SpecsHillel Wayne
 
Building Web-API without Rails, Registration or SMS
Building Web-API without Rails, Registration or SMSBuilding Web-API without Rails, Registration or SMS
Building Web-API without Rails, Registration or SMSPivorak MeetUp
 

Ähnlich wie Validating forms (and more) with the HTML5 pattern attribute (20)

GCSECS-DefensiveDesign.pptx
GCSECS-DefensiveDesign.pptxGCSECS-DefensiveDesign.pptx
GCSECS-DefensiveDesign.pptx
 
Web Forms People Don't Hate
Web Forms People Don't HateWeb Forms People Don't Hate
Web Forms People Don't Hate
 
The vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQLThe vJUG talk about jOOQ: Get Back in Control of Your SQL
The vJUG talk about jOOQ: Get Back in Control of Your SQL
 
Como NÃO testar o seu projeto de Software. DevDay 2014
Como NÃO testar o seu projeto de Software. DevDay 2014Como NÃO testar o seu projeto de Software. DevDay 2014
Como NÃO testar o seu projeto de Software. DevDay 2014
 
Basic testing with selenium
Basic testing with seleniumBasic testing with selenium
Basic testing with selenium
 
Manage Your Data In A B-Boy Stance
Manage Your Data In A B-Boy StanceManage Your Data In A B-Boy Stance
Manage Your Data In A B-Boy Stance
 
Asp
AspAsp
Asp
 
Rails and security
Rails and securityRails and security
Rails and security
 
Mountebank and you
Mountebank and youMountebank and you
Mountebank and you
 
What's Your Problem?
What's Your Problem?What's Your Problem?
What's Your Problem?
 
Advanced SQL Injection
Advanced SQL InjectionAdvanced SQL Injection
Advanced SQL Injection
 
Sql Injection Adv Owasp
Sql Injection Adv OwaspSql Injection Adv Owasp
Sql Injection Adv Owasp
 
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and BeyondWebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
WebTest - Efficient Functional Web Testing with HtmlUnit and Beyond
 
What you need to know bout html5
What you need to know bout html5What you need to know bout html5
What you need to know bout html5
 
Web Security Mistakes: Trusting The Client
Web Security Mistakes: Trusting The ClientWeb Security Mistakes: Trusting The Client
Web Security Mistakes: Trusting The Client
 
Data validation in web applications
Data validation in web applicationsData validation in web applications
Data validation in web applications
 
Getting Started With Testing
Getting Started With TestingGetting Started With Testing
Getting Started With Testing
 
Your Tests Are Not Your Specs
Your Tests Are Not Your SpecsYour Tests Are Not Your Specs
Your Tests Are Not Your Specs
 
2018 03 20_biological_databases_part3
2018 03 20_biological_databases_part32018 03 20_biological_databases_part3
2018 03 20_biological_databases_part3
 
Building Web-API without Rails, Registration or SMS
Building Web-API without Rails, Registration or SMSBuilding Web-API without Rails, Registration or SMS
Building Web-API without Rails, Registration or SMS
 

Mehr von cliener

Designing for Learning Difficulties @ Web Directions Design 2019
Designing for Learning Difficulties @ Web Directions Design 2019Designing for Learning Difficulties @ Web Directions Design 2019
Designing for Learning Difficulties @ Web Directions Design 2019cliener
 
Skeleton screens early draft for JSFoo 2017
Skeleton screens early draft for JSFoo 2017Skeleton screens early draft for JSFoo 2017
Skeleton screens early draft for JSFoo 2017cliener
 
Bad Form @ Form, Function & Class 2016
Bad Form @ Form, Function & Class 2016Bad Form @ Form, Function & Class 2016
Bad Form @ Form, Function & Class 2016cliener
 
Blurred lines
Blurred linesBlurred lines
Blurred linescliener
 
Bad Form @ JSConf Asia 2014
Bad Form @ JSConf Asia 2014Bad Form @ JSConf Asia 2014
Bad Form @ JSConf Asia 2014cliener
 
Building & Breaking Web Forms with Quaid-JS
Building & Breaking Web Forms with Quaid-JSBuilding & Breaking Web Forms with Quaid-JS
Building & Breaking Web Forms with Quaid-JScliener
 

Mehr von cliener (7)

Designing for Learning Difficulties @ Web Directions Design 2019
Designing for Learning Difficulties @ Web Directions Design 2019Designing for Learning Difficulties @ Web Directions Design 2019
Designing for Learning Difficulties @ Web Directions Design 2019
 
Skeleton screens early draft for JSFoo 2017
Skeleton screens early draft for JSFoo 2017Skeleton screens early draft for JSFoo 2017
Skeleton screens early draft for JSFoo 2017
 
Bad Form @ Form, Function & Class 2016
Bad Form @ Form, Function & Class 2016Bad Form @ Form, Function & Class 2016
Bad Form @ Form, Function & Class 2016
 
No Fear
No FearNo Fear
No Fear
 
Blurred lines
Blurred linesBlurred lines
Blurred lines
 
Bad Form @ JSConf Asia 2014
Bad Form @ JSConf Asia 2014Bad Form @ JSConf Asia 2014
Bad Form @ JSConf Asia 2014
 
Building & Breaking Web Forms with Quaid-JS
Building & Breaking Web Forms with Quaid-JSBuilding & Breaking Web Forms with Quaid-JS
Building & Breaking Web Forms with Quaid-JS
 

Kürzlich hochgeladen

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 

Kürzlich hochgeladen (20)

Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 

Validating forms (and more) with the HTML5 pattern attribute

  • 1. Validating Forms (AND MORE) WITH THE HTML5 Pattern Attribute @cliener
  • 2. HTML5 RECAP http://wufoo.com/html5/ Before I get stuck into patterns, I’ll quickly go through some of the important parts of HTML5 forms. If you want to play along at home, have a look at Wufoo’s HTML Forms guide.
  • 3. HTML5 RECAP <input  type="email"> Most of the new input types come with awesome custom keyboards for iOS and more recent Android (amongst others). Some browser versions offer basic validation in but inconsistent implementations mean they can’t be relied upon. The key new inputs types are “email”,
  • 7. HTML5 RECAP <input  type="datetime"> Unfortunately “datetime”, “time” and “year” input types have been marked as “in danger” by the W3C due to poor and inconsistent browser support. There’s something of a chicken and egg situation when it comes to standards and browser support. Unfortunately for the HTML5 date and time inputs,
  • 8. the chicken looks something like this.
  • 9. HTML5 RECAP <input  required> Important attributes to note are “required”,
  • 10. HTML5 RECAP <input  placeholder=              "dd/mm/yyyy"> “placeholder”
  • 11. PATTERNS <input  pattern="/d*"> and, of course, “pattern”. Patterns allow you to provide a regular expression string primarily for input validation. A numeric regulation expression like the this one can trigger a numeric keyboard. You’ll often see the above pattern as “[0-9]*” because most people don’t know how to write regular expressions to save themselves.
  • 12. NOW YOU HAVE TWO PROBLEMS http://evolt.org/node/36435 I can’t remember the origin so I’ll call it an old saying: “You have a problem which can be solved with a regular expression. Now you have two problems.” I won’t pretend regular expressions are the easiest to write however a good guide the one on Evolt will certainly make life easier for you.
  • 13. PATTERNS /d*/ .test("12345"); >>>  true I find the JS console (in a browser near you) are a handy way to test out regular expressions. This one matches any numeric value
  • 14. PATTERNS /d*/ .test("Once  I  caught  a              fish  alive"); >>>  false And correctly returns false to a string.
  • 15. POSTCODE /d{4}/ .test("605"); >>>  false Australian postcodes are easily matched with this pattern - exactly four digits - returning false here for “605”
  • 17. YEAR /d{4}|d{2}/ .test("13"); >>>  true Getting slightly more complex with a pipe which acts as an “or” switch, we can match either two or four digit years.
  • 18. TIME /(([0-­‐1]d)|(2[0-­‐3])) :[0-­‐5]d/ .test("08:37"); >>>  true Square brackets specify a range of values, round brackets group sub-expressions together: here matching a twenty hour time value.
  • 19. TIME /(([0-­‐1]?d)|(2[0-­‐3])) (:|.)[0-­‐5]d/ .test("8.37"); >>>  true With a slight modification, we’re now matching a wider range of natural inputs.
  • 23. At this point I can understand if you’re a little shocked, so I’ll pull it back a little.
  • 24. EMAIL /w+@w+.w+/ .test("a@b.c") >>>  true Email addresses are often something of a mine field but, on the surface, the pattern is fairly simple: “a@b.c”
  • 25. EMAIL /w+@w+.w+/ .test("cli+ner@                  server.com.au"); >>>  true Already we’re matching better than most email validation rules out there.
  • 26. EMAIL /w+@w+.w+/ .test("1337@server.com"); >>>  true Except the simplicity soon gets us unstuck when we get false positives. Given how scary date validation was, it’s tempting to see what Google has to offer
  • 27. EMAIL /(?:(?:rn)?[  t])*(?:(?:(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[  t]))*"(?:(?:rn)?[  t])*) (?:.(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[  t]))*"(?:(?:rn)? [  t])*))*@(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[  t])*)(?:.(?:(?:r n)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[  t])*))*|(?:[^()<>@,;:".[]  000-­‐ 031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[  t]))*"(?:(?:rn)?[  t])*)*<(?:(?:rn)?[  t])*(?:@(?:[^()<>@,;:".[]  000-­‐ 031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[  t])*)(?:.(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:r n)?[  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[  t])*))*(?:,@(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(? =[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[  t])*)(?:.(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:". []]))|[([^[]r]|.)*](?:(?:rn)?[  t])*))*)*:(?:(?:rn)?[  t])*)?(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r ]|.|(?:(?:rn)?[  t]))*"(?:(?:rn)?[  t])*)(?:.(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r ]|.|(?:(?:rn)?[  t]))*"(?:(?:rn)?[  t])*))*@(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]| .)*](?:(?:rn)?[  t])*)(?:.(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)? [  t])*))*>(?:(?:rn)?[  t])*)|(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[  t]))*"(?:(?:rn)? [  t])*)*:(?:(?:rn)?[  t])*(?:(?:(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[  t]))*"(?:(?:r n)?[  t])*)(?:.(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[  t]))*"(?:(?:r n)?[  t])*))*@(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[  t])*)(?:.(?: (?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[  t])*))*|(?:[^()<>@,;:".[]   000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[  t]))*"(?:(?:rn)?[  t])*)*<(?:(?:rn)?[  t])*(?:@(?:[^()<>@,;:".[]   000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[  t])*)(?:.(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?: (?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[  t])*))*(?:,@(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+| Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[  t])*)(?:.(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;: ".[]]))|[([^[]r]|.)*](?:(?:rn)?[  t])*))*)*:(?:(?:rn)?[  t])*)?(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^ "r]|.|(?:(?:rn)?[  t]))*"(?:(?:rn)?[  t])*)(?:.(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^ "r]|.|(?:(?:rn)?[  t]))*"(?:(?:rn)?[  t])*))*@(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[] r]|.)*](?:(?:rn)?[  t])*)(?:.(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?: rn)?[  t])*))*>(?:(?:rn)?[  t])*)(?:,s*(?:(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)? [  t]))*"(?:(?:rn)?[  t])*)(?:.(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)? [  t]))*"(?:(?:rn)?[  t])*))*@(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)? [  t])*)(?:.(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[  t])*))*|(?: [^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[  t]))*"(?:(?:rn)?[  t])*)*<(?:(?:rn)?[  t])*(?:@(?: [^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[  t])*)(?:.(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]   000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[  t])*))*(?:,@(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?: (?:rn)?[  t])+|Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[  t])*)(?:.(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+| Z|(?=[["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[  t])*))*)*:(?:(?:rn)?[  t])*)?(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[ ["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[  t]))*"(?:(?:rn)?[  t])*)(?:.(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[ ["()<>@,;:".[]]))|"(?:[^"r]|.|(?:(?:rn)?[  t]))*"(?:(?:rn)?[  t])*))*@(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[ ["()<>@,;:".[]]))|[([^[]r]|.)*](?:(?:rn)?[  t])*)(?:.(?:(?:rn)?[  t])*(?:[^()<>@,;:".[]  000-­‐031]+(?:(?:(?:rn)?[  t])+|Z|(?=[["()<>@,;:". []]))|[([^[]r]|.)*](?:(?:rn)?[  t])*))*>(?:(?:rn)?[  t])*))*)?;s*)/ .test("ha@ha.ha"); >>>  true http://www.codinghorror.com/blog/2005/02/regex-use-vs-regex-abuse.html And here is 6.2KB of RFC standard-compliant email regular expression.
  • 28. Which brings me to a major problem when regular expressions.
  • 29. Unfortunately, a fair number of programmers out in the wild haven’t quite worked out regular expressions yet so you need to be really careful about what you’re write.
  • 31. SECURITY As a whole, password validation is awful.
  • 32. SECURITY Over-validation is a great way to make people hate you
  • 33. SECURITY because, as much as you might think otherwise, you don’t know as much about them as you think you do.
  • 34. SECURITY But then there are people like, presumably, Bob.
  • 35. And here be dragyns. In the last couple of years, millions of passwords - hashed and otherwise - have been grabbed from various online services which means that everything we though we knew about password validation is, in essence, wrong. This also means that enforced password validation is probably wrong too. So, please don’t. Invest your energy into two factor authentication or something else that’s actually secure rather than incurring the wrath of the users who do know what they’re doing.
  • 36. CREDIT CARDS "4123  5678  9012  3456" .replace(/(s)/g,  ""); >>>  "4123567890123456" While I’ve shown how awesome regular expressions are for pattern validation, they can also manipulate data. Right here is everything you need to strip spaces from a credit card number so I can enter it with spaces as it is on my card. You no longer have any excuses.
  • 37. ERROR MESSAGES <input  pattern="d{4}"   title="Please  enter  a   valid  postcode  e.g.   3000"> Rather crucial when doing pattern validation is presenting a meaningful error message to users. In HTML5, browsers are abusing the title attribute to this end. You can also set the .setCustomValidity() DOM property but title will work for most instances.
  • 38. ERROR MESSAGES The results aren’t perfect, but they’re a whole lot better than server validation.
  • 39. In summary, are regular expressions better than kittens? I think the answer is definitively yes.
  • 41. FURTHER READING HTML5 Rocks: Constraint Validation: Native Client Side Validation for Web Forms http://www.html5rocks.com/en/tutorials/ forms/constraintvalidation/