The algorithm that browsers run to determine the validity of a form when it is submitted is called constraint validation. To constrain data or check validity, the algorithm utilizes new HTML5 attributes such as min
, max
, step
, pattern
, and required
, as well as existing attributes such as maxlength
and type
.
In HTML5, basic constraints are declared in two different ways:
By choosing the most semantically appropriate value for the
type
attribute of the<input>
elementBy setting values on validation-related attributes and allowing basic constraints to be described in a simple way without the need for JavaScript
Nowadays, an increasing number of browsers are supporting the constraint validation API, and it's becoming more and more reliable. However, HTML5 constraint validation doesn't remove the need for validation on the server side.
At a high level, this API covers the following features:
Form fields have a validity property
Form fields...