Input Password maxLength Attribute

Definition and Usage

maxLength Set or return the value of the password field's maxlength attribute.

The HTML maxlength attribute specifies the maximum number of characters allowed in the password field.

Tip:To set or return the width of the password field (in characters), use size attribute.

See also:

HTML Reference Manual:HTML <input> maxlength Attribute

Example

Example 1

Get the maximum number of characters allowed in the specified password field:

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

Try it yourself

Example 2

Set the maximum number of characters allowed in the password field:

document.getElementById("myPsw").maxLength = "10";

Try it yourself

Syntax

Return maxLength attribute:

passwordObject.maxLength

Set maxLength attribute:

passwordObject.maxLength = integer

Attribute Value

Value Description
integer Specifies the maximum number of characters allowed in the password field.

Technical Details

Return Value: A number representing the maximum number of characters allowed in the password field.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support Support Support Support Support