--- title: ValidityState slug: Web/API/ValidityState translation_of: Web/API/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.
setCustomValidity()
method.maxlength
for {{domxref("HTMLInputElement")}} or {{domxref("HTMLTextAreaElement")}} objects. Note: This will never be true
in Gecko, because elements' values are prevented from being longer than maxlength
.minlength
for {{domxref("HTMLInputElement")}} or {{domxref("HTMLTextAreaElement")}} objects.email
or url
).Specification | Status | Comment |
---|---|---|
{{ SpecName('HTML WHATWG', 'forms.html#the-constraint-validation-api', 'ValidityState') }} | {{Spec2('HTML WHATWG')}} | Live Standard |
{{ SpecName('HTML5.1', '#the-constraint-validation-api', 'ValidityState') }} | {{Spec2('HTML5.1')}} | No change from the previous snapshot {{SpecName('HTML5 W3C')}}. |
{{ SpecName('HTML5 W3C', 'forms.html#the-constraint-validation-api', 'ValidityState') }} | {{Spec2('HTML5 W3C')}} | First snapshot of {{SpecName('HTML WHATWG')}} containing this interface. |
{{ CompatibilityTable() }}
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | {{ CompatVersionUnknown() }} | {{CompatVersionUnknown}} | {{ CompatVersionUnknown }} | 10 | {{ CompatVersionUnknown() }} | 10.0.3 |
badInput |
{{CompatUnknown}} | {{CompatVersionUnknown}} | {{CompatGeckoDesktop(29)}} | {{CompatUnknown}} | {{CompatUnknown}} | 10.0.3 |
Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{CompatVersionUnknown}} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} |
badIndput |
{{CompatUnknown}} | {{CompatUnknown}} | {{CompatGeckoMobile(29)}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |