Open In App

HTML DOM Input Password minLength Property

The HTML DOM Input Password minLength Property is used to set or return the value of a minLength attribute of a password field. It specifies the minimum number of characters that have been allowed in the element. 

Syntax: 



passwordObject.minLength
passwordObject.minLength = integer

Property Values:

Return Value: It returns a numeric value that represents the minimum number of characters that have been allowed in the Password field. 



Example 1: This example illustrates how to return the property. 




<!DOCTYPE html>
<html>
   
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
    <h2>DOM Input Password minLength Property</h2>
    <form id="myGeeks">
        Password: <input type="password" id="myPsw"
                         minlength="8">
    </form>
    <br><br>
    <button onclick="myFunction()">
        Click Here!
    </button>
    <p id="demo"
       style="color:green;font-size:25px;">
    </p>
   
    <script>
        function myFunction() {
            let x = document.getElementById(
                "myPsw").minLength;
 
            document.getElementById(
                "demo").innerHTML = x;
        }
    </script>
</body>
   
</html>

Output:

 

Example 2: This example illustrates how to set the property. 




<!DOCTYPE html>
<html>
   
<body style="text-align:center;">
    <h1 style="color:green;">
        GeeksForGeeks
    </h1>
    <h2>DOM Input Password minLength Property</h2>
    <form id="myGeeks">
        Password:
          <input type="password" id="myPsw" minlength="8">
    </form>
    <br><br>
    <button onclick="myFunction()">
        Click Here!
    </button>
    <p id="demo"
       style="color:green;font-size:25px;">
    </p>
   
    <script>
        function myFunction() {
            let x = document.getElementById(
                "myPsw").minLength = "9";
 
            document.getElementById("demo").innerHTML
                = "The value of the minlength "
                + "attribute set to" + x;
        }
    </script>
</body>
   
</html>

Output:

 

Supported Browsers:


Article Tags :