The Constraint Validation API
Native form validation is great, but at times you may want to do more with it by perhaps adding some custom validation or creating your own error-reporting framework. The Constraint Validation API has a series of objects, properties, and methods aimed at giving you the flexibility to extend the browser’s validation system or to roll your own.
The first property is willValidate
, which returns true
or false
if the element it’s called on will be validated—not if its value is valid, but if the validation process will be applied. You might find it more useful to think of the property as willBeValidated. By default, all form elements return true
, unless they are explicitly set not to—for example, by using the disabled ...
Get The Modern Web now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.