Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

HTMLFormElement.checkValidity() — checking form validity

The form.checkValidity() method checks constraints on controls associated with a form and returns a boolean. It neither submits the form nor displays the browser's standard validation messages.

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

form.checkValidity()

HTMLFormElement.checkValidity is a browser Web API method, not a function defined by ECMAScript. Calling form.checkValidity() takes no arguments and synchronously returns true when every control eligible for validation satisfies its constraints; otherwise, it returns false.

The check covers controls associated with the form, not just its descendants. Controls disabled through disabled are skipped. If no controls are eligible for validation, the result is true. The method fires an invalid event at each invalid control; canceling that event does not change the result to true.

The method neither submits the form nor itself displays the standard error interface. Use form.reportValidity() to check and report problems to the user. Browser validation does not replace server-side validation.

The example creates a form with a required text field. The empty field produces false and one invalid event; after assigning Ada, the result is true. Run the code in a browser: a Node.js 24 environment alone does not establish availability of this API.

Examples

(() => {
  const form = document.createElement('form');
  const input = document.createElement('input');
  input.required = true;
  form.append(input);

  let invalidEvents = 0;
  input.addEventListener('invalid', () => { invalidEvents += 1; });

  console.log(form.checkValidity());
  input.value = 'Ada';
  console.log(form.checkValidity());
  console.log(invalidEvents);
})();

Result

false
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.

Sources