Back to Content

HTMLFormElement: reportValidity() method

files/en-us/web/api/htmlformelement/reportvalidity/index.md

latest1.0 KB
Original Source

{{APIRef("HTML DOM")}}

The reportValidity() method of the {{domxref("HTMLFormElement")}} interface performs the same validity checking steps as the {{domxref("HTMLFormElement.checkValidity", "checkValidity()")}} method. In addition, for each {{domxref("HTMLElement/invalid_event", "invalid")}} event that was fired and not canceled, the browser displays the problem to the user.

Syntax

js-nolint
reportValidity()

Parameters

None.

Return value

Returns true if the associated controls' values have no validity problems; otherwise, returns false.

Example

js
document.forms["my-form"].addEventListener("submit", () => {
  document.forms["my-form"].reportValidity();
});

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also