HTMLButtonElement: setCustomValidity() メソッド

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since December 2018.

setCustomValidity()HTMLButtonElement インターフェイスのメソッドで、 独自の検証メッセージを <button> 要素に設定します。空文字列を使用すると、要素に独自の検証エラーがないことを示します。

構文

js
setCustomValidity(string)

引数

string

エラーメッセージが入った文字列。空文字列を指定すると、独自の検証エラーがすべて除去されます。

返値

なし (undefined)。

js
const errorButton = document.getElementById("checkErrors");
const errors = issuesToReport();
if (errors) {
  errorButton.setCustomValidity("エラーがあります");
} else {
  errorButton.setCustomValidity("");
}

仕様書

Specification
HTML
# dom-cva-setcustomvalidity-dev

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobile
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
setCustomValidity

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
See implementation notes.

関連情報