HTMLSelectElement: checkValidity() メソッド

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.

checkValidity()HTMLSelectElement インターフェイスのメソッドで、その要素が適用された制約検証ルールを満たしているかどうかを示す論理値を返します。false の場合は、メソッドは要素上で invalid イベントも発行します。checkValidity() には既定でブラウザーの動作が設定されていないため、この invalid イベントをキャンセルしても効果はありません。

メモ: HTML の <select> 要素で、validationMessage が null 以外の値を持つものは不正なものと見なされ、CSS の :invalid 擬似クラスに一致し、checkValidity() が false を返すようになります。 HTMLSelectElement.setCustomValidity() メソッドを使用して、HTMLSelectElement.validationMessage を空文字列に設定すると、validity 状態が妥当となります。

構文

js
checkValidity()

引数

なし。

返値

要素の値に妥当性の問題がなければ true を返し、そうでなければ false を返します。

次の例では、checkValidity() を呼び出すと true または false が返ります。

js
const element = document.getElementById("mySelect");
console.log(element.checkValidity());

仕様書

Specification
HTML
# dom-cva-checkvalidity-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
checkValidity

Legend

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

Full support
Full support

関連情報