Password maxLengthProperty

Password 对象参考手册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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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>

Try it Yourself »


Password 对象参考手册Password Object Other Extensions