Password maxLengthProperty
Password Object
Definition and Usage
The maxLength property sets or returns the maximum number of characters allowed in a password field.
Syntax
Set the maxLength property:
passwordObject.maxLength=integer
Return the maxLength property:
passwordObject.maxLength
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the maxLength property
Examples
Examples
The following example shows the maximum number of characters allowed in the specified password field:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial(example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("pwd").maxLength;
alert(x);
}
</script>
</head>
<body>
<form>
Password: <input type="password" id="pwd" maxlength="8">
</form>
<button type="button" onclick="displayResult()">Show the maximum number of characters allowed</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Example Tutorial(example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("pwd").maxLength;
alert(x);
}
</script>
</head>
<body>
<form>
Password: <input type="password" id="pwd" maxlength="8">
</form>
<button type="button" onclick="displayResult()">Show the maximum number of characters allowed</button>
</body>
</html>
Try it Yourself »
Password Object Other Extensions