SlideShare a Scribd company logo
1 of 17
Significant Work. Extraordinary People. SRA.
Form Validation with HTML5
Ryan R. Williams
Date: 07/09/2013
2Significant Work. Extraordinary People. SRA.
What?
• HTML5 client-side <form> validation
• New <input> types and attributes make it easy
• One drawback … you still need to perform server side validation
3Significant Work. Extraordinary People. SRA.
HTML 4
• Client-side validation requires JavaScript
• Custom code, jQuery validate, etc.
• Extra work to give the user optimal UX
4Significant Work. Extraordinary People. SRA.
HTML5
• New <input> types and attributes
• Browsers have built-in client-side validation
5Significant Work. Extraordinary People. SRA.
For Example
6Significant Work. Extraordinary People. SRA.
Required fields
<input type=“text” required>
7Significant Work. Extraordinary People. SRA.
Regex with pattern attribute
<input type=“text” required
pattern=“(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)dd”
placeholder=“mm/dd/yyyy”>
8Significant Work. Extraordinary People. SRA.
Other Validations
<input type=“email” required
placeholder=“Enter your email”>
<input type=“url” required
placeholder=“Website”>
<input type=“number” value=“1”
min=“1” max=“10” required>
9Significant Work. Extraordinary People. SRA.
HTML5 Forms + CSS3
• New pseudo classes better for UX
• Visual cues and feedback to guide the user
10Significant Work. Extraordinary People. SRA.
:required and :optional
label + input:required {
background:hsl(180, 50%, 90%);
}
label + input:optional {
border:1px dotted hsl(180, 50%, 90%);
background:hsl(300, 50%, 90%);
}
11Significant Work. Extraordinary People. SRA.
:valid and :invalid
label + input:valid,
label + input:in-range {
background:hsl(120, 50%, 90%);
border-color:hsl(120, 50%, 90%);
}
label + input:invalid,
label + input:out-of-range {
background:hsl(0, 50%, 50%);
border-color:hsl(0, 50%, 90%);
}
12Significant Work. Extraordinary People. SRA.
No validation?
<form novalidate>
…
</form>
13Significant Work. Extraordinary People. SRA.
Cross browser?
Firefox? Yes. (4.0+) 
Safari? Yes. (4.0+) 
Chrome? Yes. (3.0+) 
Opera? Yes. (10.0+) 
iPhone? No. 
Android? No. 
Internet Explorer? Something like that... (10.0+) 
http://diveintohtml5.info/forms.html#validation
14Significant Work. Extraordinary People. SRA.
JavaScript fallback…
• Modernizr library for HTML5 detection
//only polyfill forms, if placeholder or autofocus are not supported
if(!Modernizr.input.placeholder || !Modernizr.input.autofocus){
jQuery.webshims.polyfill('forms');
}
15Significant Work. Extraordinary People. SRA.
Further info
• A Form of Madness
http://diveintohtml5.info/forms.html
• Forward Thinking Form Validation
http://alistapart.com/article/forward-thinking-form-validation
• New Form Features in HTML5
http://dev.opera.com/articles/view/new-form-features-in-html5/
• Modernizr JavaScript Library
http://modernizr.com/
16Significant Work. Extraordinary People. SRA.
Can also be used in…
• In browser extensions
• Greasemonkey scripts
• Prototyping/designing in the browser
17Significant Work. Extraordinary People. SRA.
Questions?

More Related Content

What's hot

Efficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram ArnoldEfficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram ArnoldMarakana Inc.
 
Unobtrusive JavaScript
Unobtrusive JavaScriptUnobtrusive JavaScript
Unobtrusive JavaScriptVitaly Baum
 
Anatomy of payment systems in Drupal 8
Anatomy of payment systems in Drupal 8Anatomy of payment systems in Drupal 8
Anatomy of payment systems in Drupal 8Oleg Natalushko
 
Learn about Eclipse e4 from Lars Vogel at SF-JUG
Learn about Eclipse e4 from Lars Vogel at SF-JUGLearn about Eclipse e4 from Lars Vogel at SF-JUG
Learn about Eclipse e4 from Lars Vogel at SF-JUGMarakana Inc.
 
FreshBooks API
FreshBooks APIFreshBooks API
FreshBooks APIBoris Mann
 
Practical PHP by example Jan Leth-Kjaer
Practical PHP by example   Jan Leth-KjaerPractical PHP by example   Jan Leth-Kjaer
Practical PHP by example Jan Leth-KjaerCOMMON Europe
 
HTML5 e Css3 - 7 | WebMaster & WebDesigner
HTML5 e Css3 - 7 | WebMaster & WebDesignerHTML5 e Css3 - 7 | WebMaster & WebDesigner
HTML5 e Css3 - 7 | WebMaster & WebDesignerMatteo Magni
 
Top 5 Magento Secure Coding Best Practices
Top 5 Magento Secure Coding Best PracticesTop 5 Magento Secure Coding Best Practices
Top 5 Magento Secure Coding Best PracticesOleksandr Zarichnyi
 
Introduction to StratusForms #SayNoToInfoPath
Introduction to StratusForms #SayNoToInfoPathIntroduction to StratusForms #SayNoToInfoPath
Introduction to StratusForms #SayNoToInfoPathMark Rackley
 
PLAT-15 Forms Config, Customization, and Extension
PLAT-15 Forms Config, Customization, and ExtensionPLAT-15 Forms Config, Customization, and Extension
PLAT-15 Forms Config, Customization, and ExtensionAlfresco Software
 
WDE08 Designing for interaction with Ajax
WDE08 Designing for interaction with AjaxWDE08 Designing for interaction with Ajax
WDE08 Designing for interaction with AjaxSatoshi Kikuchi
 
Escape from the automation hell
Escape from the automation hellEscape from the automation hell
Escape from the automation hellNikita Simonovets
 
Top 10 HTML5 features every developer should know!
Top 10 HTML5 features every developer should know!Top 10 HTML5 features every developer should know!
Top 10 HTML5 features every developer should know!Gill Cleeren
 

What's hot (14)

Efficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram ArnoldEfficient Rails Test Driven Development (class 4) by Wolfram Arnold
Efficient Rails Test Driven Development (class 4) by Wolfram Arnold
 
Unobtrusive JavaScript
Unobtrusive JavaScriptUnobtrusive JavaScript
Unobtrusive JavaScript
 
Anatomy of payment systems in Drupal 8
Anatomy of payment systems in Drupal 8Anatomy of payment systems in Drupal 8
Anatomy of payment systems in Drupal 8
 
Learn about Eclipse e4 from Lars Vogel at SF-JUG
Learn about Eclipse e4 from Lars Vogel at SF-JUGLearn about Eclipse e4 from Lars Vogel at SF-JUG
Learn about Eclipse e4 from Lars Vogel at SF-JUG
 
FreshBooks API
FreshBooks APIFreshBooks API
FreshBooks API
 
Practical PHP by example Jan Leth-Kjaer
Practical PHP by example   Jan Leth-KjaerPractical PHP by example   Jan Leth-Kjaer
Practical PHP by example Jan Leth-Kjaer
 
HTML5 e Css3 - 7 | WebMaster & WebDesigner
HTML5 e Css3 - 7 | WebMaster & WebDesignerHTML5 e Css3 - 7 | WebMaster & WebDesigner
HTML5 e Css3 - 7 | WebMaster & WebDesigner
 
Top 5 Magento Secure Coding Best Practices
Top 5 Magento Secure Coding Best PracticesTop 5 Magento Secure Coding Best Practices
Top 5 Magento Secure Coding Best Practices
 
Introduction to StratusForms #SayNoToInfoPath
Introduction to StratusForms #SayNoToInfoPathIntroduction to StratusForms #SayNoToInfoPath
Introduction to StratusForms #SayNoToInfoPath
 
PLAT-15 Forms Config, Customization, and Extension
PLAT-15 Forms Config, Customization, and ExtensionPLAT-15 Forms Config, Customization, and Extension
PLAT-15 Forms Config, Customization, and Extension
 
Apex & jQuery Mobile
Apex & jQuery MobileApex & jQuery Mobile
Apex & jQuery Mobile
 
WDE08 Designing for interaction with Ajax
WDE08 Designing for interaction with AjaxWDE08 Designing for interaction with Ajax
WDE08 Designing for interaction with Ajax
 
Escape from the automation hell
Escape from the automation hellEscape from the automation hell
Escape from the automation hell
 
Top 10 HTML5 features every developer should know!
Top 10 HTML5 features every developer should know!Top 10 HTML5 features every developer should know!
Top 10 HTML5 features every developer should know!
 

Similar to form_validation_with_html5

Clean separation
Clean separationClean separation
Clean separationatorreno
 
Yesplan: 10 Years later
Yesplan: 10 Years laterYesplan: 10 Years later
Yesplan: 10 Years laterPharo
 
Building towards a Composite API Framework in Salesforce
Building towards a Composite API Framework in SalesforceBuilding towards a Composite API Framework in Salesforce
Building towards a Composite API Framework in SalesforceSalesforce Developers
 
Implementing Awesome: An HTML5/CSS3 Workshop
Implementing Awesome: An HTML5/CSS3 WorkshopImplementing Awesome: An HTML5/CSS3 Workshop
Implementing Awesome: An HTML5/CSS3 WorkshopShoshi Roberts
 
HTML5 Hacking - Yahoo! Open Hack Day
HTML5 Hacking - Yahoo! Open Hack DayHTML5 Hacking - Yahoo! Open Hack Day
HTML5 Hacking - Yahoo! Open Hack DayTed Drake
 
Quality Development with CSS3
Quality Development with CSS3Quality Development with CSS3
Quality Development with CSS3Shay Howe
 
Introduction to GraphQL at API days
Introduction to GraphQL at API daysIntroduction to GraphQL at API days
Introduction to GraphQL at API daysyann_s
 
Presentation html5 css3 by thibaut
Presentation html5 css3 by thibautPresentation html5 css3 by thibaut
Presentation html5 css3 by thibautThibaut Baillet
 
SMC304 Serverless Orchestration with AWS Step Functions
SMC304 Serverless Orchestration with AWS Step FunctionsSMC304 Serverless Orchestration with AWS Step Functions
SMC304 Serverless Orchestration with AWS Step FunctionsAmazon Web Services
 
NEW LAUNCH! Serverless Apps with AWS Step Functions
NEW LAUNCH! Serverless Apps with AWS Step FunctionsNEW LAUNCH! Serverless Apps with AWS Step Functions
NEW LAUNCH! Serverless Apps with AWS Step FunctionsAmazon Web Services
 
UI Design with HTML5 & CSS3
UI Design with HTML5 & CSS3UI Design with HTML5 & CSS3
UI Design with HTML5 & CSS3Shay Howe
 
Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016Doris Chen
 
Open Social In The Enterprise
Open Social In The EnterpriseOpen Social In The Enterprise
Open Social In The EnterpriseTim Moore
 
Delightful steps to becoming a functioning user of Step Functions
Delightful steps to becoming a functioning user of Step FunctionsDelightful steps to becoming a functioning user of Step Functions
Delightful steps to becoming a functioning user of Step FunctionsYan Cui
 
Building Custom Controls to Visualize Data (UI5Con 2016 Frankfurt)
Building Custom Controls to Visualize Data (UI5Con 2016 Frankfurt)Building Custom Controls to Visualize Data (UI5Con 2016 Frankfurt)
Building Custom Controls to Visualize Data (UI5Con 2016 Frankfurt)Maximilian Lenkeit
 
Mark Tortoricci - Talent42 2015
Mark Tortoricci - Talent42 2015Mark Tortoricci - Talent42 2015
Mark Tortoricci - Talent42 2015Talent42
 
Frontend developer Roadmap .pdf
Frontend developer Roadmap .pdfFrontend developer Roadmap .pdf
Frontend developer Roadmap .pdfDurgeshSinghLodhi1
 
Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014
Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014
Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014Rackspace Academy
 
Cassandra 2.1
Cassandra 2.1Cassandra 2.1
Cassandra 2.1jbellis
 

Similar to form_validation_with_html5 (20)

Clean separation
Clean separationClean separation
Clean separation
 
Yesplan: 10 Years later
Yesplan: 10 Years laterYesplan: 10 Years later
Yesplan: 10 Years later
 
Building towards a Composite API Framework in Salesforce
Building towards a Composite API Framework in SalesforceBuilding towards a Composite API Framework in Salesforce
Building towards a Composite API Framework in Salesforce
 
Implementing Awesome: An HTML5/CSS3 Workshop
Implementing Awesome: An HTML5/CSS3 WorkshopImplementing Awesome: An HTML5/CSS3 Workshop
Implementing Awesome: An HTML5/CSS3 Workshop
 
HTML5 Hacking - Yahoo! Open Hack Day
HTML5 Hacking - Yahoo! Open Hack DayHTML5 Hacking - Yahoo! Open Hack Day
HTML5 Hacking - Yahoo! Open Hack Day
 
Quality Development with CSS3
Quality Development with CSS3Quality Development with CSS3
Quality Development with CSS3
 
Introduction to GraphQL at API days
Introduction to GraphQL at API daysIntroduction to GraphQL at API days
Introduction to GraphQL at API days
 
Presentation html5 css3 by thibaut
Presentation html5 css3 by thibautPresentation html5 css3 by thibaut
Presentation html5 css3 by thibaut
 
SMC304 Serverless Orchestration with AWS Step Functions
SMC304 Serverless Orchestration with AWS Step FunctionsSMC304 Serverless Orchestration with AWS Step Functions
SMC304 Serverless Orchestration with AWS Step Functions
 
NEW LAUNCH! Serverless Apps with AWS Step Functions
NEW LAUNCH! Serverless Apps with AWS Step FunctionsNEW LAUNCH! Serverless Apps with AWS Step Functions
NEW LAUNCH! Serverless Apps with AWS Step Functions
 
UI Design with HTML5 & CSS3
UI Design with HTML5 & CSS3UI Design with HTML5 & CSS3
UI Design with HTML5 & CSS3
 
Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016Practical tipsmakemobilefaster oscon2016
Practical tipsmakemobilefaster oscon2016
 
HTML 5 & CSS 3
HTML 5 & CSS 3HTML 5 & CSS 3
HTML 5 & CSS 3
 
Open Social In The Enterprise
Open Social In The EnterpriseOpen Social In The Enterprise
Open Social In The Enterprise
 
Delightful steps to becoming a functioning user of Step Functions
Delightful steps to becoming a functioning user of Step FunctionsDelightful steps to becoming a functioning user of Step Functions
Delightful steps to becoming a functioning user of Step Functions
 
Building Custom Controls to Visualize Data (UI5Con 2016 Frankfurt)
Building Custom Controls to Visualize Data (UI5Con 2016 Frankfurt)Building Custom Controls to Visualize Data (UI5Con 2016 Frankfurt)
Building Custom Controls to Visualize Data (UI5Con 2016 Frankfurt)
 
Mark Tortoricci - Talent42 2015
Mark Tortoricci - Talent42 2015Mark Tortoricci - Talent42 2015
Mark Tortoricci - Talent42 2015
 
Frontend developer Roadmap .pdf
Frontend developer Roadmap .pdfFrontend developer Roadmap .pdf
Frontend developer Roadmap .pdf
 
Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014
Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014
Software as a Service workshop / Unlocked: the Hybrid Cloud 12th May 2014
 
Cassandra 2.1
Cassandra 2.1Cassandra 2.1
Cassandra 2.1
 

form_validation_with_html5

  • 1. Significant Work. Extraordinary People. SRA. Form Validation with HTML5 Ryan R. Williams Date: 07/09/2013
  • 2. 2Significant Work. Extraordinary People. SRA. What? • HTML5 client-side <form> validation • New <input> types and attributes make it easy • One drawback … you still need to perform server side validation
  • 3. 3Significant Work. Extraordinary People. SRA. HTML 4 • Client-side validation requires JavaScript • Custom code, jQuery validate, etc. • Extra work to give the user optimal UX
  • 4. 4Significant Work. Extraordinary People. SRA. HTML5 • New <input> types and attributes • Browsers have built-in client-side validation
  • 5. 5Significant Work. Extraordinary People. SRA. For Example
  • 6. 6Significant Work. Extraordinary People. SRA. Required fields <input type=“text” required>
  • 7. 7Significant Work. Extraordinary People. SRA. Regex with pattern attribute <input type=“text” required pattern=“(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.](19|20)dd” placeholder=“mm/dd/yyyy”>
  • 8. 8Significant Work. Extraordinary People. SRA. Other Validations <input type=“email” required placeholder=“Enter your email”> <input type=“url” required placeholder=“Website”> <input type=“number” value=“1” min=“1” max=“10” required>
  • 9. 9Significant Work. Extraordinary People. SRA. HTML5 Forms + CSS3 • New pseudo classes better for UX • Visual cues and feedback to guide the user
  • 10. 10Significant Work. Extraordinary People. SRA. :required and :optional label + input:required { background:hsl(180, 50%, 90%); } label + input:optional { border:1px dotted hsl(180, 50%, 90%); background:hsl(300, 50%, 90%); }
  • 11. 11Significant Work. Extraordinary People. SRA. :valid and :invalid label + input:valid, label + input:in-range { background:hsl(120, 50%, 90%); border-color:hsl(120, 50%, 90%); } label + input:invalid, label + input:out-of-range { background:hsl(0, 50%, 50%); border-color:hsl(0, 50%, 90%); }
  • 12. 12Significant Work. Extraordinary People. SRA. No validation? <form novalidate> … </form>
  • 13. 13Significant Work. Extraordinary People. SRA. Cross browser? Firefox? Yes. (4.0+)  Safari? Yes. (4.0+)  Chrome? Yes. (3.0+)  Opera? Yes. (10.0+)  iPhone? No.  Android? No.  Internet Explorer? Something like that... (10.0+)  http://diveintohtml5.info/forms.html#validation
  • 14. 14Significant Work. Extraordinary People. SRA. JavaScript fallback… • Modernizr library for HTML5 detection //only polyfill forms, if placeholder or autofocus are not supported if(!Modernizr.input.placeholder || !Modernizr.input.autofocus){ jQuery.webshims.polyfill('forms'); }
  • 15. 15Significant Work. Extraordinary People. SRA. Further info • A Form of Madness http://diveintohtml5.info/forms.html • Forward Thinking Form Validation http://alistapart.com/article/forward-thinking-form-validation • New Form Features in HTML5 http://dev.opera.com/articles/view/new-form-features-in-html5/ • Modernizr JavaScript Library http://modernizr.com/
  • 16. 16Significant Work. Extraordinary People. SRA. Can also be used in… • In browser extensions • Greasemonkey scripts • Prototyping/designing in the browser
  • 17. 17Significant Work. Extraordinary People. SRA. Questions?