DOM HTMLFormElement.checkValidity() Method
The checkValidity() method checks whether every field in a form passes its validation rules. reportValidity() also shows the browser's error messages.
Description
The checkValidity() method returns whether all the form's controls satisfy their validation constraints, such as required, type="email", min and pattern. Invalid controls fire an invalid event. reportValidity() does the same but also shows the browser's error message and focuses the first invalid field. Both exist on individual inputs too, and setCustomValidity() adds your own rules.
Validation runs on every control that takes part in validation; disabled and read-only fields, and buttons, are skipped. Listening for the invalid event on fields lets you show your own error messages, and the CSS :user-invalid pseudo-class styles invalid fields only after the user has interacted with them.
The browser's built-in checks are a convenience for users, not a security measure, since anyone can bypass them; always validate data again on the server.
Syntax
form.checkValidity()
form.reportValidity()Return Value
true if every control in the form is valid, otherwise false.
Example
Browser Support
The following information will show you the current browser support for the HTMLFormElement.checkValidity() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





