Skip to content

New pages: HTMLTextAreaElement min and max length #35877

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions files/en-us/web/api/htmltextareaelement/maxlength/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: "HTMLTextAreaElement: maxLength property"
short-title: maxLength
slug: Web/API/HTMLTextAreaElement/maxLength
page-type: web-api-instance-property
browser-compat: api.HTMLTextAreaElement.maxLength
---

{{ApiRef("HTML DOM")}}

The **`maxLength`** property of the {{domxref("HTMLTextAreaElement")}} interface indicates the maximum number of characters (in UTF-16 code units) allowed to be entered for the value of the {{HTMLElement("textarea")}} element, and the maximum number of characters allowed for the value to be valid. It reflects the element's [`maxlength`](/en-US/docs/Web/HTML/Element/textarea#maxlength) attribute. `-1` means there is no limit on the length of the value.

> [!NOTE]
> Browsers generally prevent users from entering more characters than the `maxlength` attribute allows. Should the length be longer, the element is considered invalid and the {{domxref("ValidityState")}} object's {{domxref("ValidityState.tooLong", "tooLong")}} property will be `true`.

## Value

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

## Example

Given the following HTML:

```html
<p>
<label for="comment">Comment</label>
<textarea id="comment" minlength="10" maxlength="200" /></textarea>
</p>
```

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

```js
const textareaElement = document.querySelector("#comment");
console.log(`Element's maxLength: ${textareaElement.maxLength}`); // "Element's maxlength: 200"
textareaElement.maxLength = 220; // updates the element's maxlength attribute value
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("HTMLTextAreaElement.value")}}
- {{domxref("HTMLTextAreaElement.minLength")}}
- {{domxref("ValidityState.tooLong")}}
51 changes: 51 additions & 0 deletions files/en-us/web/api/htmltextareaelement/minlength/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
---
title: "HTMLTextAreaElement: minLength property"
short-title: minLength
slug: Web/API/HTMLTextAreaElement/minLength
page-type: web-api-instance-property
browser-compat: api.HTMLTextAreaElement.minLength
---

{{ApiRef("HTML DOM")}}

The **`minLength`** property of the {{domxref("HTMLTextAreaElement")}} interface indicates the minimum number of characters (in UTF-16 code units) required for the value of the {{HTMLElement("textarea")}} element to be valid. It reflects the element's [`minlength`](/en-US/docs/Web/HTML/Element/textarea#minlength) attribute. `-1` means there is no minimum length requirement.

> [!NOTE]
> If the textarea has a value, and that value has fewer characters than the `minlength` attribute requires, the element is considered invalid and the {{domxref("ValidityState")}} object's {{domxref("ValidityState.tooShort", "tooShort")}} property will be `true`.

## Value

A number representing the element's `minlength` if present or `-1`.

## Example

Given the following HTML:

```html
<p>
<label for="comment">Comment</label>
<textarea id="comment" minlength="10" maxlength="200" /></textarea>
</p>
```

You can use the `minLength` property to retrieve or set the `<textarea>`'s `minlength` attribute value:

```js
const textareaElement = document.querySelector("#comment");
console.log(`Element's minLength: ${textareaElement.minLength}`); // "Element's minlength: 10"
textareaElement.minLength = 5; // updates the element's minlength attribute value
```

## Specifications

{{Specifications}}

## Browser compatibility

{{Compat}}

## See also

- {{domxref("HTMLTextAreaElement.value")}}
- {{domxref("HTMLTextAreaElement.maxLength")}}
- {{domxref("ValidityState.tooShort")}}