ValidityState
ValidityState
介面表示了一個元素目前在其檢核條件下驗證的正確性狀態(validity states)。同時,它們也可以協助解釋元素值檢核失敗的原因,如果元素值為不合法的。
屬性
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
(en-US) 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
(en-US) Read only-
Is a
Boolean
indicating the value does not match the specifiedpattern
. ValidityState.rangeOverflow
(en-US) Read only-
Is a
Boolean
indicating the value is greater than the maximum specified by themax
attribute. ValidityState.rangeUnderflow
(en-US) Read only-
Is a
Boolean
indicating the value is less than the minimum specified by themin
attribute. ValidityState.stepMismatch
(en-US) 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
(en-US) Read only-
Is a
Boolean
indicating the value exceeds the specifiedmaxlength
forHTMLInputElement
orHTMLTextAreaElement
(en-US) objects. Note: This will never betrue
in Gecko, because elements' values are prevented from being longer thanmaxlength
. ValidityState.tooShort
(en-US) Read only-
Is a
Boolean
indicating the value fails to meet the specifiedminlength
forHTMLInputElement
orHTMLTextAreaElement
(en-US) objects. ValidityState.typeMismatch
(en-US) 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
(en-US) Read only-
Is a
Boolean
indicating the element has arequired
attribute, but no value.
規範
Specification |
---|
HTML Standard # the-constraint-validation-api:validitystate-3 |
瀏覽器相容性
BCD tables only load in the browser