The checkValidity() method of the ElementInternals interface checks if the element meets any constraint validation rules applied to it.
If checkValidity returns false then a cancelable invalid event is fired on the element.
The checkValidity() method of the ElementInternals interface checks if the element meets any constraint validation rules applied to it.
If checkValidity returns false then a cancelable invalid event is fired on the element.
js
checkValidity()
None.
A boolean value, true if the element meets all validation constraints.
NotSupportedError DOMException
Thrown if the element does not have its formAssociated property set to true.
In the following example ElementInternals.setValidity() is used to indicate that the element does not meet validation rules. Calling checkValidity() returns false. After calling setValidity again, this time indicating that all rules are marked false, checkValidity() returns true.
js
let element = document.getElementById("join-checkbox"); element.internals_.setValidity({ valueMissing: true }, "my message"); console.log(element.internals_.checkValidity()); // false element.internals_.setValidity({}); console.log(element.internals_.checkValidity()); // true
| Specification |
|---|
| HTML Standard # dom-elementinternals-checkvalidity |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
checkValidity |
77 | 79 | 98 | No | 64 | 16.4 | 77 | 77 | 98 | 55 | 16.4 | 12.0 |
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/ElementInternals/checkValidity