Skip to content
Related Articles

Related Articles

HTML | DOM Input Password minLength Property
  • Last Updated : 21 Oct, 2020

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 which represents the minimum number of characters that have been allowed in the Password field.

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



filter_none

edit
close

play_arrow

link
brightness_4
code

<!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() {
            var x = document.getElementById(
                        "myPsw").minLength;
  
            document.getElementById(
                    "demo").innerHTML = x;
        
    </script>
</body>
  
</html>

chevron_right


Output:

  • Before clicking on the button:
  • After clicking on the button:

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

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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() {
            var x = document.getElementById(
                    "myPsw").minLength = "9";
  
            document.getElementById("demo").innerHTML
                    = "The value of the minlength "
                    + "attribute set to" + x;
        
    </script>
</body>
  
</html>                   

chevron_right


Output:

  • Before clicking on the button:
  • After clicking on the button:

full-stack-img

My Personal Notes arrow_drop_up
Recommended Articles
Page :