Input Search maxLength Property
Example
Get the maximum number of characters allowed in the search field:
var x = document.getElementById("mySearch").maxLength;
x
The output is:
30
Try it »
Definition and Usage
The maxLength property sets or returns the value of the maxlength attribute of the search field.
The maxLength property describes the maximum number of characters allowed in the search field.
The default value is 524288.
Tip: If you need to set or return the length (number of characters) of the search field, use size attribute.
Browser support





All major browsers support the maxLength property.
Syntax
Return the maxLength property:
searchObject
.maxLength
Set the maxLength property:
searchObject
.maxLength=
number
Attribute values
| Value | Description |
|---|---|
| number | Describes the maximum number of characters allowed in the search field; the default is 524288 |
Technical Details
| Return Value: | A number representing the maximum number of characters allowed in the search field. |
|---|
More examples
Example
Change the maximum number of characters allowed in the search field:
document.getElementById("mySearch").maxLength = "8";
Try it »
Related pages
HTML Reference Manual: HTML maxlength property
Input Search Object