ValidityState
The ValidityState interface represents the validity states that an element can be in, with respect to constraint validation. Together, they help explain why an element's value fails to validate, if it's not valid.
Properties
For each of these Boolean properties, a value of true indicates that the specified reason validation may have failed is true, with the exception of the valid property, which is true if the element's value obeys all constraints.
badInputRead only-
A boolean value that is
trueif the user has provided input that the browser is unable to convert. customErrorRead only-
A boolean value indicating whether the element's custom validity message has been set to a non-empty string by calling the element's
setCustomValidity()method. patternMismatchRead only-
A boolean value that is
trueif the value does not match the specifiedpattern, andfalseif it does match. Iftrue, the element matches the:invalidCSS pseudo-class. rangeOverflowRead only-
A boolean value that is
trueif the value is greater than the maximum specified by themaxattribute, orfalseif it is less than or equal to the maximum. Iftrue, the element matches the:invalidand:out-of-rangeand CSS pseudo-classes. rangeUnderflowRead only-
A boolean value that is
trueif the value is less than the minimum specified by theminattribute, orfalseif it is greater than or equal to the minimum. Iftrue, the element matches the:invalidand:out-of-rangeCSS pseudo-classes. stepMismatchRead only-
A boolean value that is
trueif the value does not fit the rules determined by thestepattribute (that is, it's not evenly divisible by the step value), orfalseif it does fit the step rule. Iftrue, the element matches the:invalidand:out-of-rangeCSS pseudo-classes. tooLongRead only-
A boolean value that is
trueif the value exceeds the specifiedmaxlengthforHTMLInputElementorHTMLTextAreaElementobjects, orfalseif its length is less than or equal to the maximum length. Note: This property is nevertruein Gecko, because elements' values are prevented from being longer thanmaxlength. Iftrue, the element matches the:invalidand:out-of-rangeCSS pseudo-classes. tooShortRead only-
A boolean value that is
trueif the value fails to meet the specifiedminlengthforHTMLInputElementorHTMLTextAreaElementobjects, orfalseif its length is greater than or equal to the minimum length. Iftrue, the element matches the:invalidand:out-of-rangeCSS pseudo-classes. typeMismatchRead only-
A boolean value that is
trueif the value is not in the required syntax (whentypeisemailorurl), orfalseif the syntax is correct. Iftrue, the element matches the:invalidCSS pseudo-class. validRead only-
A boolean value that is
trueif the element meets all its validation constraints, and is therefore considered to be valid, orfalseif it fails any constraint. Iftrue, the element matches the:validCSS pseudo-class; the:invalidCSS pseudo-class otherwise. valueMissingRead only-
A boolean value that is
trueif the element has arequiredattribute, but no value, orfalseotherwise. Iftrue, the element matches the:invalidCSS pseudo-class.
Specifications
| Specification |
|---|
| HTML Standard # the-constraint-validation-api:validitystate-3 |
Browser compatibility
BCD tables only load in the browser