我們的志工尚未將此文章翻譯為 正體中文 (繁體) 版本。加入我們,幫忙翻譯!
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.
ValidityState.badInput
Read only- Is a
Boolean
indicating the user has provided input that the browser is unable to convert. ValidityState.customError
Read only- Is a
Boolean
indicating the element's custom validity message has been set to a non-empty string by calling the element'ssetCustomValidity()
method. ValidityState.patternMismatch
Read only- Is a
Boolean
indicating the value does not match the specifiedpattern
. ValidityState.rangeOverflow
Read only- Is a
Boolean
indicating the value is greater than the maximum specified by themax
attribute. ValidityState.rangeUnderflow
Read only- Is a
Boolean
indicating the value is less than the minimum specified by themin
attribute. ValidityState.stepMismatch
Read only- Is a
Boolean
indicating the value does not fit the rules determined by thestep
attribute (that is, it's not evenly divisible by the step value). ValidityState.tooLong
Read only- Is a
Boolean
indicating the value exceeds the specifiedmaxlength
forHTMLInputElement
orHTMLTextAreaElement
objects. Note: This will never betrue
in Gecko, because elements' values are prevented from being longer thanmaxlength
. ValidityState.typeMismatch
Read only- Is a
Boolean
indicating the value is not in the required syntax (whentype
isemail
orurl
). ValidityState.valid
Read only- Is a
Boolean
indicating the element meets all constraint validations, and is therefore considered to be valid. ValidityState.valueMissing
Read only- Is a
Boolean
indicating the element has arequired
attribute, but no value.
Specifications
Specification | Status | Comment |
---|---|---|
WHATWG HTML Living Standard The definition of 'ValidityState' in that specification. |
Living Standard | Live Standard |
HTML5.1 The definition of 'ValidityState' in that specification. |
Working Draft | No change from the previous snapshot HTML5. |
HTML5 The definition of 'ValidityState' in that specification. |
Recommendation | First snapshot of WHATWG HTML Living Standard containing this interface. |
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | 10 | (Yes) | ? |
badInput |
? | 29 (29) | ? | ? | ? |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
badIndput |
? | ? | 29.0 (29) | ? | ? | ? |