HTMLInputElement: pattern プロパティ
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
pattern
は HTMLInputElement
インターフェイスのプロパティで、空ではない <input>
の値が一致すべき正規表現を表します。これは、<input>
要素の pattern
属性を反映します。
pattern
プロパティは、text
、search
、url
、tel
、email
、password
の型で有効です。これは、入力フィールドの value
が制約検証を通過するために一致する必要がある正規表現を定義します。
空ではない値が制約に適合しない場合、ValidityState
オブジェクトの読み取り専用プロパティである patternMismatch
が true になります。
値
文字列です。
例
js
const inputElement = document.getElementById("year");
console.log(input.pattern);
仕様書
Specification |
---|
HTML # dom-input-pattern |
ブラウザーの互換性
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
pattern |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
関連情報
<input>
HTMLInputElement.value
- クライアント側の検証
:valid
および:invalid
擬似クラス