CKTIS / JavaScript
HTMLInputElement.checkValidity() — checking an input's validity
The checkValidity() method checks the constraints of one input and returns a boolean. For an invalid input that participates in validation, it fires invalid but does not itself display an error message.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
input.checkValidity()HTMLInputElement.checkValidity is an instance method called as input.checkValidity(), without arguments. It returns false when the input participates in validation and violates its constraints; otherwise, it returns true.
Constraints depend on the input type and attributes such as required, pattern, min, and max. A disabled input does not participate in validation: true therefore does not necessarily mean its value is valid. The willValidate property indicates whether the input participates.
On a false result, the method fires an invalid event; canceling it does not change the result. Unlike reportValidity(), it does not display an error message. It neither submits the form nor checks other inputs.
This browser API is defined by the HTML Living Standard, not ECMAScript. It is supported in current browser engines; having Node 24 in a repository does not establish support for this API.
Examples
const input = document.createElement('input');
input.type = 'text';
input.required = true;
let invalidEvents = 0;
input.addEventListener('invalid', () => { invalidEvents += 1; });
console.log(input.checkValidity());
input.value = 'Ada';
console.log(input.checkValidity());
input.value = '';
input.disabled = true;
console.log(input.checkValidity());
console.log(invalidEvents);Result
false true true 1
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.