HTMLInputElement: minLength プロパティ

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.

minLengthHTMLInputElement インターフェイスのプロパティで、この <input> 要素の値として必要な最小文字数(UTF-16 コード単位)を示します。これは、この要素の minlength 属性を反映します。-1 は、必要な最小文字数がないことを意味します。

メモ: 入力に値があり、その値が minlength 属性で要求される文字数よりも少ない場合、その要素は無効と見なされ、ValidityState オブジェクトの tooShort プロパティが true になります。

存在する場合は要素の minlength を表す数値、さもなくば -1

次の HTML があったとします。

html
<p>
  <label for="password">パスワード</label>
  <input id="password" type="password" minlength="8" maxlength="20" />
</p>

minLength プロパティを使用して、<input>minlength 属性値を取得または設定することができます。

js
const inputElement = document.querySelector("#password");
console.log(`要素の minLength: ${inputElement.minLength}`); // "要素の minlength: 8"
inputElement.minLength = 12; // この要素の minlength 属性値を更新

仕様書

Specification
HTML
# dom-input-minlength

ブラウザーの互換性

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
minLength

Legend

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

Full support
Full support

関連情報