Created
October 15, 2013 00:12
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks.