In this example, the user registration form now validates to ensure that the data received meets certain requirements.
Using the required
attribute, you can define fields that can't be submitted with an empty value. The user name, password, email, state, birth year, and user agreement fields shown below are required.
You can use the pattern
attribute to be sure that the value a user types into a field matches a certain format. The pattern attribute accepts a regular expression which the value must match before the data
can be submitted. The password field here uses the pattern attribute to check that the value is more than 8 characters long and the telephone field uses it to ensure a proper format.
When you use a number or range field, you can constrain input to a minimum and maximum value. The birth year field in this form now requires a minimum value of 1910 and a maximum value of 1997. You also set the step allowed between values to do things like only accept even numbers.