{{APIRef("HTML DOM")}} {{gecko_minversion_header("2.0")}}
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.
- {{domxref("ValidityState.badInput")}} {{ReadOnlyInline}}
- Is a {{jsxref("Boolean")}} is indicating if if the user has provided input that the browser is unable to convert.
- {{domxref("ValidityState.customError")}} {{ReadOnlyInline}}
- Is a {{jsxref("Boolean")}} is indicating if the element's custom validity message has been set to a non-empty string by calling the element's
setCustomValidity()
method. - {{domxref("ValidityState.patternMismatch")}} {{ReadOnlyInline}}
- Is a {{jsxref("Boolean")}} is indicating if the value does not match the specified {{htmlattrxref("pattern", "input")}}.
- {{domxref("ValidityState.rangeOverflow")}} {{ReadOnlyInline}}
- Is a {{jsxref("Boolean")}} is indicating if the value is greater than the maximum specified by the {{htmlattrxref("max", "input")}} attribute.
- {{domxref("ValidityState.rangeUnderflow")}} {{ReadOnlyInline}}
- Is a {{jsxref("Boolean")}} is indicating if the value is less than the minimum specified by the {{htmlattrxref("min", "input")}} attribute.
- {{domxref("ValidityState.stepMismatch")}} {{ReadOnlyInline}}
- Is a {{jsxref("Boolean")}} is indicating if the value does not fit the rules determined by the {{htmlattrxref("step", "input")}} attribute (that is, it's not evenly divisible by the step value).
- {{domxref("ValidityState.tooLong")}} {{ReadOnlyInline}}
- Is a {{jsxref("Boolean")}} is indicating if the value exceeds the specified
maxlength
for {{domxref("HTMLInputElement")}} or {{domxref("HTMLTextAreaElement")}} objects. Note: This will never betrue
in Gecko, because elements' values are prevented from being longer thanmaxlength
. - {{domxref("ValidityState.typeMismatch")}} {{ReadOnlyInline}}
- Is a {{jsxref("Boolean")}} is indicating if the value is not in the required syntax (when {{htmlattrxref("type", "input")}} is
email
orurl
). - {{domxref("ValidityState.valid")}} {{ReadOnlyInline}}
- Is a {{jsxref("Boolean")}} is indicating if the element meets all constraint validations, and is therefore considered to be valid.
- {{domxref("ValidityState.valueMissing")}} {{ReadOnlyInline}}
- Is a {{jsxref("Boolean")}} is indicating if the element has a {{htmlattrxref("required", "input")}} attribute, but no value.
Specifications
Specification | Status | Comment |
---|---|---|
{{ SpecName('HTML WHATWG', 'constraints.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. |
Browser compatibility
{{ CompatibilityTable() }}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatUnknown() }} |
badInput |
{{CompatUnknown}} | {{CompatGeckoDesktop(29)}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} |
badIndput |
{{CompatUnknown}} | {{CompatUnknown}} | {{CompatGeckoMobile(29)}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |