Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confirm 2 password fields via jQuery

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">
like image 874
4WebDev Avatar asked Nov 26 '25 10:11

4WebDev


1 Answers

change the input field names,

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

and use the following script,

$("#password-2").change(function(){
     if($(this).val() != $("#password-1").val()){
               alert("values do not match");
               //more processing here
     }
});

If you want to use more functions, you should think of using a jquery plugin like jquery Validate

like image 193
redDevil Avatar answered Nov 29 '25 00:11

redDevil



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!