LOGBOOK

HELP

Quiz Entry - updated: 2026.07.14

How does the HTML5 Constraint Validation API work?

The Constraint Validation API lets you check whether an input meets its HTML constraints via checkValidity() and inspect the result through the validity object and validationMessage.

Key method: checkValidity()

const input = document.querySelector("#email");

if (input.checkValidity()) {
    console.log("Valid!");
} else {
    console.log("Invalid:", input.validationMessage);
}

Validation properties on input elements:

Property Type Meaning
validity.valid Boolean Overall valid state
validity.valueMissing Boolean Required field is empty
validity.typeMismatch Boolean Wrong type (email, url)
validity.tooShort Boolean Below minlength
validity.tooLong Boolean Above maxlength
validity.rangeUnderflow Boolean Below min value
validity.rangeOverflow Boolean Above max value
validity.patternMismatch Boolean Doesn't match pattern
validationMessage String Browser's error message

From Quiz: WEBT / Frontend | Updated: Jul 14, 2026