SlideShare a Scribd company logo
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 (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
Marakana Inc.
 
Unobtrusive JavaScript
Unobtrusive JavaScriptUnobtrusive JavaScript
Unobtrusive JavaScript
Vitaly 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 8
Oleg 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-JUG
Marakana Inc.
 
FreshBooks API
FreshBooks APIFreshBooks API
FreshBooks API
Boris 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-Kjaer
COMMON Europe
 
HTML5 e Css3 - 7 | WebMaster & WebDesigner
HTML5 e Css3 - 7 | WebMaster & WebDesignerHTML5 e Css3 - 7 | WebMaster & WebDesigner
HTML5 e Css3 - 7 | WebMaster & WebDesigner
Matteo 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 Practices
Oleksandr Zarichnyi
 
Introduction to StratusForms #SayNoToInfoPath
Introduction to StratusForms #SayNoToInfoPathIntroduction to StratusForms #SayNoToInfoPath
Introduction to StratusForms #SayNoToInfoPath
Mark 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 Extension
Alfresco Software
 
Apex & jQuery Mobile
Apex & jQuery MobileApex & jQuery Mobile
Apex & jQuery Mobile
Christian Rokitta
 
WDE08 Designing for interaction with Ajax
WDE08 Designing for interaction with AjaxWDE08 Designing for interaction with Ajax
WDE08 Designing for interaction with Ajax
Satoshi Kikuchi
 
Escape from the automation hell
Escape from the automation hellEscape from the automation hell
Escape from the automation hell
Nikita 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
 
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
Marakana Inc.
 
Unobtrusive JavaScript
Unobtrusive JavaScriptUnobtrusive JavaScript
Unobtrusive JavaScript
Vitaly 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 8
Oleg 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-JUG
Marakana Inc.
 
FreshBooks API
FreshBooks APIFreshBooks API
FreshBooks API
Boris 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-Kjaer
COMMON Europe
 
HTML5 e Css3 - 7 | WebMaster & WebDesigner
HTML5 e Css3 - 7 | WebMaster & WebDesignerHTML5 e Css3 - 7 | WebMaster & WebDesigner
HTML5 e Css3 - 7 | WebMaster & WebDesigner
Matteo 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 Practices
Oleksandr Zarichnyi
 
Introduction to StratusForms #SayNoToInfoPath
Introduction to StratusForms #SayNoToInfoPathIntroduction to StratusForms #SayNoToInfoPath
Introduction to StratusForms #SayNoToInfoPath
Mark 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 Extension
Alfresco Software
 
WDE08 Designing for interaction with Ajax
WDE08 Designing for interaction with AjaxWDE08 Designing for interaction with Ajax
WDE08 Designing for interaction with Ajax
Satoshi Kikuchi
 
Escape from the automation hell
Escape from the automation hellEscape from the automation hell
Escape from the automation hell
Nikita 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
 

Similar to form_validation_with_html5 (20)

HTML5 workshop, forms
HTML5 workshop, formsHTML5 workshop, forms
HTML5 workshop, forms
Robert Nyman
 
Html5 inputs
Html5 inputsHtml5 inputs
Html5 inputs
Chris Love
 
A Sensational Exposé With Bewildering Demonstrations
A Sensational Exposé With Bewildering DemonstrationsA Sensational Exposé With Bewildering Demonstrations
A Sensational Exposé With Bewildering Demonstrations
Peter Gasston
 
Accessible dynamic forms
Accessible dynamic formsAccessible dynamic forms
Accessible dynamic forms
Dylan Barrell
 
Web Forms People Don't Hate
Web Forms People Don't HateWeb Forms People Don't Hate
Web Forms People Don't Hate
cliener
 
JavaScript - Chapter 14 - Form Handling
 JavaScript - Chapter 14 - Form Handling   JavaScript - Chapter 14 - Form Handling
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
 
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
cliener
 
HTML5 Forms - KISS time - Fronteers
HTML5 Forms - KISS time - FronteersHTML5 Forms - KISS time - Fronteers
HTML5 Forms - KISS time - Fronteers
Robert Nyman
 
HTML5 Forms OF DOOM
HTML5 Forms OF DOOMHTML5 Forms OF DOOM
HTML5 Forms OF DOOM
Stephanie Hobson
 
Data validation in web applications
Data validation in web applicationsData validation in web applications
Data validation in web applications
srkirkland
 
Knolx j query-form-validation-slides
Knolx j query-form-validation-slidesKnolx j query-form-validation-slides
Knolx j query-form-validation-slides
Knoldus Inc.
 
Html5 Forms in Squiz Matrix - Dave Letorey
Html5 Forms in Squiz Matrix - Dave LetoreyHtml5 Forms in Squiz Matrix - Dave Letorey
Html5 Forms in Squiz Matrix - Dave Letorey
Squiz
 
HTML5 Mullet: Forms & Input Validation
HTML5 Mullet: Forms & Input ValidationHTML5 Mullet: Forms & Input Validation
HTML5 Mullet: Forms & Input Validation
Todd Anglin
 
html 5 new form attribute
html 5 new form attributehtml 5 new form attribute
html 5 new form attribute
Priyanka Rasal
 
html forms 2.pptx
html forms 2.pptxhtml forms 2.pptx
html forms 2.pptx
AmanRaja20
 
Hassliebe Onlineformulare, Enhance your Form for better UX
Hassliebe Onlineformulare, Enhance your Form for better UXHassliebe Onlineformulare, Enhance your Form for better UX
Hassliebe Onlineformulare, Enhance your Form for better UX
Peter Rozek
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
Maitree Patel
 
Web topic 22 validation on web forms
Web topic 22  validation on web formsWeb topic 22  validation on web forms
Web topic 22 validation on web forms
CK Yang
 
Forms with html5
Forms with html5Forms with html5
Forms with html5
Suvarna Pappu
 
Forms with html5 (1)
Forms with html5 (1)Forms with html5 (1)
Forms with html5 (1)
Anada Kale
 
HTML5 workshop, forms
HTML5 workshop, formsHTML5 workshop, forms
HTML5 workshop, forms
Robert Nyman
 
A Sensational Exposé With Bewildering Demonstrations
A Sensational Exposé With Bewildering DemonstrationsA Sensational Exposé With Bewildering Demonstrations
A Sensational Exposé With Bewildering Demonstrations
Peter Gasston
 
Accessible dynamic forms
Accessible dynamic formsAccessible dynamic forms
Accessible dynamic forms
Dylan Barrell
 
Web Forms People Don't Hate
Web Forms People Don't HateWeb Forms People Don't Hate
Web Forms People Don't Hate
cliener
 
JavaScript - Chapter 14 - Form Handling
 JavaScript - Chapter 14 - Form Handling   JavaScript - Chapter 14 - Form Handling
JavaScript - Chapter 14 - Form Handling
WebStackAcademy
 
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
cliener
 
HTML5 Forms - KISS time - Fronteers
HTML5 Forms - KISS time - FronteersHTML5 Forms - KISS time - Fronteers
HTML5 Forms - KISS time - Fronteers
Robert Nyman
 
Data validation in web applications
Data validation in web applicationsData validation in web applications
Data validation in web applications
srkirkland
 
Knolx j query-form-validation-slides
Knolx j query-form-validation-slidesKnolx j query-form-validation-slides
Knolx j query-form-validation-slides
Knoldus Inc.
 
Html5 Forms in Squiz Matrix - Dave Letorey
Html5 Forms in Squiz Matrix - Dave LetoreyHtml5 Forms in Squiz Matrix - Dave Letorey
Html5 Forms in Squiz Matrix - Dave Letorey
Squiz
 
HTML5 Mullet: Forms & Input Validation
HTML5 Mullet: Forms & Input ValidationHTML5 Mullet: Forms & Input Validation
HTML5 Mullet: Forms & Input Validation
Todd Anglin
 
html 5 new form attribute
html 5 new form attributehtml 5 new form attribute
html 5 new form attribute
Priyanka Rasal
 
html forms 2.pptx
html forms 2.pptxhtml forms 2.pptx
html forms 2.pptx
AmanRaja20
 
Hassliebe Onlineformulare, Enhance your Form for better UX
Hassliebe Onlineformulare, Enhance your Form for better UXHassliebe Onlineformulare, Enhance your Form for better UX
Hassliebe Onlineformulare, Enhance your Form for better UX
Peter Rozek
 
Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
Maitree Patel
 
Web topic 22 validation on web forms
Web topic 22  validation on web formsWeb topic 22  validation on web forms
Web topic 22 validation on web forms
CK Yang
 
Forms with html5 (1)
Forms with html5 (1)Forms with html5 (1)
Forms with html5 (1)
Anada Kale
 

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?