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.

badInput Read only
A Boolean that is true if the user has provided input that the browser is unable to convert.
customError Read only
A Boolean indicating whether the element's custom validity message has been set to a non-empty string by calling the element's setCustomValidity() method.
patternMismatch Read only
A Boolean that is true if the value does not match the specified pattern, and false if it does match. If true, the element matches the :invalid CSS pseudo-class.
rangeOverflow Read only
A Boolean that is true if the value is greater than the maximum specified by the max attribute, or false if it is less than or equal to the maximum. If true, the element matches the :invalid and :out-of-range and CSS pseudo-classes.
rangeUnderflow Read only
A Boolean that is true if the value is less than the minimum specified by the min attribute, or false if it is greater than or equal to the minimum. If true, the element matches the :invalid and :out-of-range CSS pseudo-classes.
stepMismatch Read only
A Boolean that is true if the value does not fit the rules determined by the step attribute (that is, it's not evenly divisible by the step value), or false if it does fit the step rule. If true, the element matches the :invalid and :out-of-range CSS pseudo-classes.
tooLong Read only
A Boolean that is true if the value exceeds the specified maxlength for HTMLInputElement or HTMLTextAreaElement objects, or false if its length is less than or equal to the maximum length. Note: This property is never true in Gecko, because elements' values are prevented from being longer than maxlength. If true, the element matches the the :invalid and :out-of-range CSS pseudo-classes.
tooShort Read only
A Boolean that is true if the value fails to meet the specified minlength for HTMLInputElement or HTMLTextAreaElement objects, or false if its length is greater than or equal to the minimum length. If true, the element matches the :invalid and :out-of-range CSS pseudo-classes.
typeMismatch Read only
A Boolean that is true if the value is not in the required syntax (when type is email or url), or false if the syntax is correct. If true, the element matches the :invalid CSS pseudo-class.
valid Read only
A Boolean that is true if the element meets all its validation constraints, and is therefore considered to be valid, or false if it fails any constraint. If true, the element matches the :valid CSS pseudo-class; the :invalid CSS pseudo-class otherwise.
valueMissing Read only
A Boolean that is true if the element has a required attribute, but no value, or false otherwise. If true, the element matches the :invalid CSS 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

DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
ValidityStateChrome Full support 15Edge Full support 12Firefox Full support 4IE Full support 10Opera Full support 12.1Safari Full support 11WebView Android Full support 4Chrome Android Full support YesFirefox Android Full support 64Opera Android Full support 12.1Safari iOS Full support 5Samsung Internet Android Full support Yes
badInputChrome Full support 25Edge Full support 14Firefox Full support 29IE No support NoOpera Full support 15Safari Full support 11WebView Android Full support 4.4Chrome Android Full support YesFirefox Android Full support 64Opera Android Full support 14Safari iOS Full support 7Samsung Internet Android Full support Yes
tooLongChrome Full support 15Edge Full support 12
Notes
Full support 12
Notes
Notes Not supported in the unlikely case of the value being initially set too long, and then changed by the user to a still incorrect state. Per caniuse.com.
Firefox Full support 4
Notes
Full support 4
Notes
Notes Not supported in the unlikely case of the value being initially set too long, and then changed by the user to a still incorrect state. Per caniuse.com.
IE Full support 10Opera Full support 15Safari Full support 11WebView Android Full support 4Chrome Android Full support YesFirefox Android Full support 64Opera Android Full support 14Safari iOS Full support 5Samsung Internet Android Full support Yes
tooShortChrome Full support 40Edge Full support 17Firefox Full support 51IE No support NoOpera Full support 27Safari Full support 11WebView Android Full support 67Chrome Android Full support YesFirefox Android Full support 64Opera Android Full support 27Safari iOS Full support 10Samsung Internet Android Full support Yes

Legend

Full support
Full support
No support
No support
See implementation notes.
See implementation notes.

See also