JavaScript Internals (521 Qs)•Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)
What are the available constraint validation DOM properties
Below are the list of some of the constraint validation DOM properties available,
validity: It provides a list of boolean properties related to the validity of an input element.validationMessage: It displays the message when the validity is false.willValidate: It indicates if an input element will be validated or not.
Practical Code Example
javascript
// HTML5 Constraint Validation DOM Properties on form inputs:
const input = document.getElementById('userEmail');
console.log(input.validity); // ValidityState object
console.log(input.validationMessage);// Browser error message string
console.log(input.willValidate); // Boolean whether element participates in validation