Skip to content

Instantly share code, notes, and snippets.

@grayghostvisuals
Created October 15, 2013 00:12
Show Gist options
  • Save grayghostvisuals/6984561 to your computer and use it in GitHub Desktop.
Save grayghostvisuals/6984561 to your computer and use it in GitHub Desktop.
A simplistic way to make sure two password fields match using jQueryValidation (http://jqueryvalidation.org/validate) Using minlength, and a custom message.
jQuery.validator.addMethod( 'passwordMatch', function(value, element) {
// The two password inputs
var password = $("#register-password").val();
var confirmPassword = $("#register-pass-confirm").val();
// Check for equality with the password inputs
if (password != confirmPassword ) {
return false;
} else {
return true;
}
}, "Your Passwords Must Match");
// ==========================================================================
// Registration Form : jquery validation
// http://jqueryvalidation.org/validate
$('#form-register').validate({
// rules
rules: {
register_password: {
required: true,
minlength: 3
},
register_pass_confirm: {
required: true,
minlength: 3,
passwordMatch: true // set this on the field you're trying to match
}
},
// messages
messages: {
register_password: {
required: "What is your password?",
minlength: "Your password must contain more than 3 characters"
},
register_pass_confirm: {
required: "You must confirm your password",
minlength: "Your password must contain more than 3 characters",
passwordMatch: "Your Passwords Must Match" // custom message for mismatched passwords
}
}
});//end validate
@Puwaga
Copy link

Puwaga commented Aug 29, 2017

thanks

@oluwaseunladeinde
Copy link

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment