This page is Ready to Use

Notice: The WebPlatform project, supported by various stewards between 2012 and 2015, has been discontinued. This site is now available on github.

customError

Summary

The element’s custom validity message has been set to a non-empty string by calling the element’s setCustomValidity() method.

Property of dom/ValidityStatedom/ValidityState

Syntax

Note: This property is read-only.

var hasErrorStatus = element.validity.customError;

Return Value

Returns an object of type BooleanBoolean

Whether the element has raised a custom error.

Examples

var elem = document.getElementById('email_addr_confirm');
elem.addEventListener('blur', verifyEmail);

function verifyEmail(evt) {
  var emlcfm= evt.srcElement;
  var eml=document.getElementById('email_addr');
  if (emlcfm.value != eml.value) {
    // the provided value doesn’t match the primary email address
    emlcfm.setCustomValidity('The two email addresses must match.');
// the emlcfm.validity.customError is true;
  } else {
    // input is valid -- reset the error state, has to be an empty string
    emlcfm.setCustomValidity('');

// the emlcfm.validity.customError is false;

 }

}

Usage

 HTML5 Web form validation

Related specifications

W3C HTML5
Working Draft
WHATWG HTML
Living Standard

Attributions