Confirm password fields via jQuery

Mar 13, 2012   //   by phpfreelancer.biz   //   Blog, Jquery Tutorial  //  No Comments

I am trying to find a small script where while typing in the two password fields and if the passwords do not match then the script will specify… I also hope to do this without having to click the Submit button.

Here are my two fields:

<input name="password" type="password" id="password-1" maxlength="30" placeholder="Password Must Be 5-30 Characters" class="text-input required password">
<input name="password" type="password" id="password-2" placeholder="Repeat Password" class="text-input required password">

You can do it like:

$('.password').change(function(){
      if($("#password-1").val() == $("#password-2").val()){
            /* they match */
      }else{
            /* they are different */
      }
 });

this will hook onto the class you put on both these fields, and whenever somebody changes either field it will perform this check.

Leave a comment

Share This Post

RSS Wordpress News