HTMLInputElement: validity property - Web APIs | MDN

Value

A ValidityState object.

Examples

The following example gets the validity state of an input element and processes it if it is not valid:

js

const input = document.getElementById("myInput");
const validityState = input.validity;
if (!validityState.valid) {
  // Test each validity state
}

Specifications

Specification
HTML
# the-constraint-validation-api:dom-cva-validity

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on by MDN contributors.