A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/maxLength below:

HTMLInputElement: maxLength property - Web APIs

HTMLInputElement: maxLength property

Baseline Widely available

The maxLength property of the HTMLInputElement interface indicates the maximum number of characters (in UTF-16 code units) allowed to be entered for the value of the <input> element, and the maximum number of characters allowed for the value to be valid. It reflects the element's maxlength attribute. -1 means there is no limit on the length of the value.

Note: Browser generally prevent users from entering more characters than the maxlength attribute allows. Should the length be longer, the element is considered invalid and the ValidityState object's tooLong property will be true.

Value

A number representing the element's maxlength if present, or -1.

Example

Given the following HTML:

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

You can use the maxLength property to retrieve or set the <input>'s maxlength attribute value:

const inputElement = document.querySelector("#password");
console.log(`Element's maxLength: ${inputElement.maxLength}`); // "Element's maxlength: 20"
inputElement.maxLength = 18; // updates the element's maxlength attribute value
Specifications Browser compatibility See also

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.3