How to use the pattern attribute?

I have already turned over the internet, even in W3school, and I only see them informing the code "ready". With keys, interrogations, bars, cipher and various other parameters.

But I found nothing explaining how to use these parameters, what are they for?

Author: gmsantos, 2017-02-04

1 answers

The pattern attribute in HTML 5 forms allows that form to be validated through a Regular Expression.

Regular expressions are a way of validating textual expressions that follow some kind of pattern and by applying this expression within the pattern parameter HTML will ensure that this pattern is satisfied.

Example:

You have a form that needs to receive the license plate of a car. This type of information in Brazil it follows a certain pattern: 3 Letters From A to Z, followed by a dash and finally 4 numbers from 0 to 9. You can express this in the following form:

<form action="#">
  <label for="placa">Placa: </label>
  <input type="text" name="website" pattern="[A-Za-z]{3}-[0-9]{4}">
  <input type="submit">
</form>

Before using the pattern attribute you need an understanding of how to work with regular expressions. Below are some articles that can help you help:

 6
Author: gmsantos, 2017-06-13 20:05:06