marse marse - 1 year ago 106
HTML Question

how to set minimum length of password

I am currently working on a html form. How do I set the minimum length of the password to 8 so that it will reject any password the user inputs that are less than 8. How to do this?

Here is the code:

<div id="login-form">
<form method="post">
<table align="center" width="30%" border="0">
<td><input type="text" name="email" placeholder="Your Email" required /></td>
<td><input type="password" name="pass" placeholder="Your Password" required /></td>
<td><button type="submit" name="btn-login">Sign In</button></td>
<td><a href="register.php">Sign Up Here</a></td>

Answer Source

If you are using HTML5 you can use the pattern and required attribute for input tag:

<input type="password" pattern=".{8,}"   required title="8 characters minimum">
<input type="password" pattern=".{8,12}" required title="8 to 12 characters">

Also there is a minlength attribute for input tags but it hasn't been implemented yet in Firefox.

<input type="password" minlength="8" required>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download