HTMLTextAreaElement: 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 theHTMLTextAreaElement interface returns a boolean value which indicates if the element meets anyconstraint validation rules applied to it. If false, the method also fires aninvalid event on the element. Because there's no default browser behavior forcheckValidity(), canceling thisinvalid event has no effect.
Note:An HTML<textarea> element with a non-nullvalidationMessage is considered invalid, will match the CSS:invalid pseudo-class, and will causecheckValidity() to return false. Use theHTMLTextAreaElement.setCustomValidity() method to set theHTMLTextAreaElement.validationMessage to the empty string to set thevalidity state to be valid.
In this article
Syntax
checkValidity()Parameters
None.
Return value
Returnstrue if the element's value has no validity problems; otherwise, returnsfalse.
Examples
In the following example, callingcheckValidity() returns eithertrue orfalse.
const element = document.getElementById("myTextArea");console.log(element.checkValidity());Specifications
| Specification |
|---|
| HTML> # dom-cva-checkvalidity-dev> |