Skip to content

Commit

Permalink
New pages: HTMLTextAreaElement min and max length (#35877)
Browse files Browse the repository at this point in the history
  • Loading branch information
estelle authored Sep 13, 2024
1 parent 5a57c5c commit 8cf200c
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
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")}}

0 comments on commit 8cf200c

Please sign in to comment.