THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

Input Search maxLength Property

Input Search Object Reference Input Search Object

Example

Get the maximum number of characters allowed in a specific search field:

var x = document.getElementById("mySearch").maxLength;

The result of x will be:

30
Try it Yourself »

Definition and Usage

The maxLength property sets or returns the value of the maxlength attribute of a search field.

The maxLength attribute specifies the maximum number of characters allowed in the search field.

The default value is 524288.

Tip: To set or return the width of an email field, in number of characters, use the size property.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The maxLength property is supported in all major browsers.


Syntax

Return the maxLength property:

searchObject.maxLength

Set the maxLength property:

searchObject.maxLength=number

Property Values

Value Description
number Specifies the maximum number of characters allowed in the search field. Default value 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 a search field:

document.getElementById("mySearch").maxLength = "8";
Try it Yourself »

Related Pages

HTML reference: HTML <input> maxlength attribute


Input Search Object Reference Input Search Object