From the course: Validating and Processing Forms with JavaScript and PHP
Unlock this course with a free trial
Join today to access over 22,400 courses taught by industry experts.
Dynamic validation with regular expressions
From the course: Validating and Processing Forms with JavaScript and PHP
Dynamic validation with regular expressions
Regular expressions give you a way to search for patterns in form fields. And that can help with validation and processing. I talked about regular expressions in the movie on constraining with regular expression patterns. The regular expression syntax in HTML5 is pretty similar to JavaScript. As a matter of fact, the HTML5 implementation is a copy of the JavaScript implementation, so you can use them mostly interchangeably. In JavaScript, you have to create a regular expression pattern and then use the search method to search for that pattern in an input field. So, you might be asking yourself, why do I need to validate for patterns, if I can just use the pattern attribute in HTML5. Well, with validation, it's important to try to be as compatible with older browsers as possible. Using regular expressions in JavaScript, will let you build validation that's compatible with older browsers. Another reason is that the pattern attribute, prevents the form from submitting but it doesn't…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Accessing forms3m 57s
-
Looking up form elements3m 35s
-
Handling focus changes2m 47s
-
Detecting the onchange event4m 31s
-
Using the selectedIndex property2m 30s
-
Dynamic validation with regular expressions7m
-
Creating a generic input validation function4m 31s
-
Validating in older browsers with Modernizr7m 32s
-
Interrupting form submission with onsubmit5m 50s
-
-
-
-
-