Easy Tutorial
❮ Prop Range Name Prop Video Texttracks ❯

Password maxLength Attribute


Definition and Usage

The maxLength attribute sets or returns the maximum number of characters allowed in the password field.

Syntax

Set the maxLength attribute:

Return the maxLength attribute:


Browser Support

All major browsers support the maxLength attribute.


Example

The following example displays the maximum number of characters allowed in a specified password field:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>tutorialpro.org(tutorialpro.org)</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()">Display the maximum number of characters allowed</button>

</body>
</html>
❮ Prop Range Name Prop Video Texttracks ❯