← 返回首页
HTMLInputElement: minLength プロパティ - Web API | MDN

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

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 2018年4月.

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

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

In this article

存在する場合は要素の 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

ブラウザーの互換性

Enable JavaScript to view this browser compatibility table.

関連情報