The pattern
attribute in HTML 5 forms allow that form to be validated through a Regular Expression
a>.
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 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. Here are some articles that can help you: