-
Notifications
You must be signed in to change notification settings - Fork 22.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New pages: HTMLTextAreaElement min and max length (#35877)
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
files/en-us/web/api/htmltextareaelement/maxlength/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
51
files/en-us/web/api/htmltextareaelement/minlength/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")}} |