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
Booleanthat istrueif the user has provided input that the browser is unable to convert. customErrorRead only- A
Booleanindicating whether the element's custom validity message has been set to a non-empty string by calling the element'ssetCustomValidity()method. patternMismatchRead only- A
Booleanthat istrueif the value does not match the specifiedpattern, andfalseif it does match. If true, the element matches the:invalidCSS pseudo-class. rangeOverflowRead only- A
Booleanthat is true if the value is greater than the maximum specified by themaxattribute, orfalseif it is less than or equal to the maximum. If true, the element matches the:invalidand:out-of-rangeand CSS pseudo-classes. rangeUnderflowRead only- A
Booleanthat istrueif the value is less than the minimum specified by theminattribute, orfalseif it is greater than or equal to the minimum. If true, the element matches the:invalidand:out-of-rangeCSS pseudo-classes. stepMismatchRead only- A
Booleanthat istrueif 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. If true, the element matches the:invalidand:out-of-rangeCSS pseudo-classes. tooLongRead only- A
Booleanthat istrueif the value exceeds the specifiedmaxlengthforHTMLInputElementorHTMLTextAreaElementobjects, or false if 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. If true, the element matches the the:invalidand:out-of-rangeCSS pseudo-classes. tooShortRead only- A
Booleanthat istrueif the value fails to meet the specifiedminlengthforHTMLInputElementorHTMLTextAreaElementobjects, orfalseif its length is greater than or equal to the minimum length. If true, the element matches the:invalidand:out-of-rangeCSS pseudo-classes. typeMismatchRead only- A
Booleanthat istrueif the value is not in the required syntax (whentypeisemailorurl), orfalseif the syntax is correct. If true, the element matches the:invalidCSS pseudo-class. validRead only- A
Booleanthat istrueif the element meets all its validation constraints, and is therefore considered to be valid, orfalseif it fails any constraint. If true, the element matches the:validCSS pseudo-class; the:invalidCSS pseudo-class otherwise. valueMissingRead only- A
Booleanthat istrueif the element has arequiredattribute, but no value, orfalseotherwise. If true, the element matches the:invalidCSS pseudo-class.
Specifications
| Specification | Status | Comment |
|---|---|---|
| HTML Living Standard The definition of 'ValidityState' in that specification. |
Living Standard | Living Standard |
| HTML 5.1 The definition of 'ValidityState' in that specification. |
Recommendation | No change from the previous snapshot HTML5. |
| HTML5 The definition of 'ValidityState' in that specification. |
Recommendation | First snapshot of HTML Living Standard containing this interface. |
Browser compatibility
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
ValidityState | Chrome Full support 15 | Edge Full support 12 | Firefox Full support 4 | IE Full support 10 | Opera Full support 12.1 | Safari Full support 11 | WebView Android Full support 4 | Chrome Android Full support Yes | Firefox Android Full support 64 | Opera Android Full support 12.1 | Safari iOS Full support 5 | Samsung Internet Android Full support Yes |
badInput | Chrome Full support 25 | Edge Full support 14 | Firefox Full support 29 | IE No support No | Opera Full support 15 | Safari Full support 11 | WebView Android Full support 4.4 | Chrome Android Full support Yes | Firefox Android Full support 64 | Opera Android Full support 14 | Safari iOS Full support 7 | Samsung Internet Android Full support Yes |
tooLong | Chrome Full support 15 | Edge
Full support
12
| Firefox
Full support
4
| IE Full support 10 | Opera Full support 15 | Safari Full support 11 | WebView Android Full support 4 | Chrome Android Full support Yes | Firefox Android Full support 64 | Opera Android Full support 14 | Safari iOS Full support 5 | Samsung Internet Android Full support Yes |
tooShort | Chrome Full support 40 | Edge Full support 17 | Firefox Full support 51 | IE No support No | Opera Full support 27 | Safari Full support 11 | WebView Android Full support 67 | Chrome Android Full support Yes | Firefox Android Full support 64 | Opera Android Full support 27 | Safari iOS Full support 10 | Samsung Internet Android Full support Yes |
Legend
- Full support
- Full support
- No support
- No support
- See implementation notes.
- See implementation notes.
