coderef

Constraint validation APIBaseline · Widely available

Methods that validate form controls before submission, such as checkValidity(), reportValidity() and setCustomValidity().

Supported in all major browsers for at least 30 months — safe to use without fallbacks. Baseline since Dec 11, 2018. Widely available since Jun 11, 2021.

Browser support

DesktopChrome
1–39Not supported
40+Supportedsince Jan 21, 2015
Current: 155
Edge
12–17Not supported
18+Supportedsince Oct 2, 2018
Current: 154
Firefox
1–50Not supported
51+Supportedsince Jan 24, 2017
Current: 157
Safari
1–10Not supported
10.1+Supportedsince Mar 27, 2017
Current: 27
MobileChrome Android
18–39Not supported
40+Supportedsince Jan 21, 2015
Current: 155
Firefox Android
4–63Not supported
64+Supportedsince Dec 11, 2018
Current: 157
Safari iOS
1–10Not supported
10.3+Supportedsince Mar 27, 2017
Current: 27

How to use

This feature is Baseline widely available — use it freely, no fallback needed.

Example

Full syntax and examples are on MDN: checkValidity.

Feature detection

JS · check before using
if ("HTMLButtonElement" in globalThis && "validationMessage" in HTMLButtonElement.prototype) {
  // HTMLButtonElement.validationMessage is available
}

Sub-features

Support for each part of the feature (56). The overall table above shows when the whole feature works.

Show 36 more
Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
HTMLObjectElement.checkValidity101245.11845
HTMLObjectElement.reportValidity40184910.1404910.3
HTMLObjectElement.setCustomValidity101245.11845
HTMLObjectElement.validationMessage101245.11845
HTMLObjectElement.validity101245.11845
HTMLObjectElement.willValidate412451844
HTMLOutputElement.checkValidity91445.11845
HTMLOutputElement.reportValidity40144910.1404910.3
HTMLOutputElement.setCustomValidity91445.11845
HTMLOutputElement.validationMessage91445.11845
HTMLOutputElement.validity91445.11845
HTMLOutputElement.willValidate91445.11845
HTMLSelectElement.checkValidity412451844
HTMLSelectElement.reportValidity40174910.1406410.3
HTMLSelectElement.setCustomValidity412451844
HTMLSelectElement.validationMessage512451844
HTMLSelectElement.validity412451844
HTMLSelectElement.willValidate212441843
HTMLTextAreaElement.checkValidity412451845
HTMLTextAreaElement.reportValidity40174910.1406410.3
HTMLTextAreaElement.setCustomValidity412451845
HTMLTextAreaElement.validationMessage512451845
HTMLTextAreaElement.validity412451845
HTMLTextAreaElement.willValidate212441843.2
ValidityState412451845
ValidityState.badInput251229725647
ValidityState.customError412451845
ValidityState.patternMismatch412451845
ValidityState.rangeOverflow412451845
ValidityState.rangeUnderflow412451845
ValidityState.stepMismatch412451845
ValidityState.tooLong4124518645
ValidityState.tooShort40175110406410
ValidityState.typeMismatch412451845
ValidityState.valid412451845
ValidityState.valueMissing412451845