web api instance property
HTMLInputElement: validity property
The validity read-only property of the HTMLInputElement interface returns a ValidityState object that represents the validity states this element is in.
Value
A ValidityState object.
Examples
The following example gets the validity state of an input element and processes it if it is not valid:
const input = document.getElementById("myInput");
const validityState = input.validity;
if (!validityState.valid) {
// Test each validity state
}
Specifications
SpecificationsStandards references are available on the canonical MDN page.
Browser compatibility
Browser compatibilityCompatibility data is available on the canonical MDN page.