How to set minimum length of password

If you are using HTML5 you can use the pattern and required attributes for the 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 does not work in some browsers:

<input type="password" minlength="8" required>

Change your button to :

<button name="btn-login">Sign In</button>

And add this code JavaScript (using jquery) :

$('button[name="btn-login"]').click(function() {
    if($('input[name="pass"]').val().length < 8) {
        alert('Minimum length = 8');
    } else {
        $('form').submit();
    }
});

Dont forget to add this condition into your PHP code.


You can use the pattern attribute:

<input pattern=".{8,}" type="password" name="pass" placeholder="Your Password" required />