Input Password maxLength Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Password

Description

The maxLength property sets or gets the maxlength attribute of a password field, which controls the maximum number of characters allowed in a password field.

Set the maxLength property with the following Values

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

Return Value

A Number, representing the maximum number of characters allowed in the password field

The following code shows how to get the maximum number of characters allowed in a specific password field:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>
Password: <input type="password" id="myPsw">

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {//from   w ww.java 2s  .co  m
    var v = document.getElementById("myPsw").maxLength;
    document.getElementById("demo").innerHTML = v;
}
</script>

</body>
</html>

Related Tutorials