Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. Web APIs
  3. HTMLInputElement
  4. minLength

HTMLInputElement: minLength property

Baseline Widely available

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

TheminLength property of theHTMLInputElement interface indicates the minimum number of characters (inUTF-16 code units) required for the value of the<input> element to be valid. It reflects the element'sminlength attribute.-1 means there is no minimum length requirement.

Note:If the input has a value, and that value has fewer characters than theminlength attribute requires, the element is considered invalid and theValidityState object'stooShort property will betrue.

Value

A number representing the element'sminlength if present or-1.

Example

Given the following HTML:

html
<p>  <label for="password">Your password</label>  <input type="password" minlength="8" maxlength="20" /></p>

You can use theminLength property to retrieve or set the<input>'sminlength attribute value:

js
const inputElement = document.querySelector("#password");console.log(`Element's minLength: ${inputElement.minLength}`); // "Element's minlength: 8"inputElement.minLength = 12; // updates the element's minlength attribute value

Specifications

Specification
HTML
# dom-input-minlength

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp