HTMLFormElement: checkValidity() method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
ThecheckValidity() method of theHTMLFormElement interface returns a boolean value which indicates if all associated controls meet anyconstraint validation rules applied to them. The method also fires aninvalid event on each invalid element, but not on the form element itself. Because there's no default browser behavior forcheckValidity(), canceling thisinvalid event has no effect.
In this article
Syntax
js
checkValidity()Parameters
None.
Return value
Returnstrue if the associated controls' values have no validity problems; otherwise, returnsfalse.
Examples
In the following example, callingcheckValidity() would returntrue if orfalse.
js
const element = document.getElementById("myForm");console.log(element.checkValidity());Specifications
| Specification |
|---|
| HTML> # dom-form-checkvalidity-dev> |