Open In App

HTML DOM Input Password minLength Property

Improve
Improve
Like Article
Like
Save
Share
Report

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: 

  • It is used to return the minLength property.
passwordObject.minLength
  • It is used to set the minLength property.
passwordObject.minLength = integer

Property Values:

  • number: It specifies a minimum number of characters that are allowed in the Password Field.

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. 

HTML




<!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. 

HTML




<!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:

  • Chrome 1+
  • Edge 12+
  • Firefox 1+
  • Opera 2+
  • Safari 1+


Last Updated : 19 Jun, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads