Quiz Entry - updated: 2026.06.20
What validation properties are available on the validity object?
The validity object exposes a boolean flag for each constraint (e.g. valueMissing, typeMismatch, tooShort, rangeOverflow, patternMismatch) plus the overall valid.
const input = document.querySelector("input");
const v = input.validity;
// true if ALL constraints pass
v.valid
// required but empty
v.valueMissing
// wrong type (email without @)
v.typeMismatch
// doesn't match pattern attribute
v.patternMismatch
// exceeds maxlength
v.tooLong
// below minlength
v.tooShort
// number below min
v.rangeUnderflow
// number above max
v.rangeOverflow
// doesn't match step attribute
v.stepMismatch
// browser can't parse (e.g., letters in number)
v.badInput
// setCustomValidity was called
v.customError
Example usage:
if (input.validity.typeMismatch) {
console.log("Please enter a valid email");
} else if (input.validity.tooShort) {
console.log("Too short!");
}