3

I'm trying to set a minimum password lenght for a login page; however, it seems that the only attribute the password (input) tag has is maxlength. I know you can use the new pattern or min attribute, but I need something that works in IE 9. Is there a simple/replacement way to solve this or will I have to use strlen?

Llama
  • 122
  • 2
  • 2
  • 8

5 Answers5

5

Some Ok answers so far.

However, this is much more a concern server-side than client. I would not be difficult to "hack" the markup or Javascript to allow a short password.

You should always check server-side as well to make sure nothing weird is going on.

To sum it all up: Use Javascript to make sure the password is longer than the minimum length and recheck it server-side to make sure the jsfunction was not bypassed in any way.

OptimusCrime
  • 14,662
  • 13
  • 58
  • 96
2

One liner:

<input type="text" onKeyPress="return ( this.value.length < 10 );"/>

This can be used to implement maxlength in Internet Explorer but you should validate the input server side, too.

Amal Murali
  • 75,622
  • 18
  • 128
  • 150
2

You must use server side solution for this problem as you never know whether user has js enabled or not..

dhaval
  • 176
  • 1
  • 1
  • 7
2

Answer from another question, try this:

<input pattern=".{3,}" required title="3 characters minimum">
<input pattern=".{5,10}" required title="5 to 10 characters">
Community
  • 1
  • 1
kurdtpage
  • 3,142
  • 1
  • 24
  • 24
1
function CheckLength(name) {

            var password = document.getElementById(name).value;

            if (password.length < 4)

                alert('should have miniumum 4 chars');

        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <input type="password" id="txtpassword" name="txtpassword" />
    <input type="submit" name="txtSubmit" onclick="CheckLength('txtpassword') " />
akash
  • 2,117
  • 4
  • 21
  • 32
  • Thank you for the answer. I guess the only way in IE 9 and below is to check the array length rather than checking it in the input tag. – Llama Jul 01 '13 at 10:18