Erico Timbang Erico Timbang - 1 year ago 105
Javascript Question

Jquery If condition on password character count

I'm having a problem with my code. There's no error in Chrome's console but it doesn't work. I wanted to count the password characters entered. The condition is that the password must be a minimum of 6 characters.

$(document).ready(function() {
$(".submit").click(function() {
if($('#regform input[type="password"]').val().length > 6) {
$('.error').html('Must have a min of 6 chars');

Can anyone explain it for me?

Answer Source

Maybe this is what you're looking for:


<input type="text" id="password" />
<input type="button" class="btnSubmit" value="Submit" />
<p class="error"></p>


  if($("#password").val().length < 6){
    $('.error').html('Must have a min of 6 chars');
    $('.error').html('Good to go.');


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download