The Constraint Validation API provides a way to implement custom form validation in web applications. It offers a set of properties and methods that allow developers to check the validity of form inputs and display custom error messages.
- validationMessage (property)
Returns a string with the validation message for the element.
- validity (property)
Returns a ValidityState object with the validity states of the element.
- willValidate (property)
Returns a boolean indicating if the element is a candidate for constraint validation.
- checkValidity (method)
Reports the validity of an input based element. Returns true if the field is valid, false otherwise. If used on a form element, it will report the validity of all fields.
- reportValidity (method)
Reports the validity of an input based element. Returns true if the field is valid, false otherwise. On top that, if the element is invalid it displays the issue to the user in the browser so long as the event isn't canceled. If used on a form element, it will report the validity of all fields and fire an invalid event on each invalid element.
- setCustomValidity (method)
Sets a custom error message and marks the field as invalid.
- invalid (event)
Fires when a submittable element has been checked and doesn't satisfy its constraints