From the course: Building Great Forms with HTML and CSS

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Input restrictions: Pattern

Input restrictions: Pattern

From the course: Building Great Forms with HTML and CSS

Start my 1-month free trial

Input restrictions: Pattern

- [Instructor] As we have seen, the HTML5 specification has made validation that much easier with the introduction of the new input types, such as email, URL and tel. And these also come packaged up with predefined validation. Whenever the value given is not met with the expected formatting , these input types will throw an error message, thus preventing submission. However, expecting every possible input scenario to be catered for is impractical. What if you have a username "zipcode", "credit card" or any other special data types that are not specified as standard input types? How do we validate those inputs? This is where the attribute pattern comes into play. The pattern attribute is only applicable on the input element. It allows us to define our own rule to validate the input value using regular expressions or regex. Again, if the value does not match the specified pattern, the input will throw an error. Regular…

Contents