Need to add a regex check to my jquery.validate script.
I have this:
$().ready(function() {
$(\"#myBlahForm\").validate({
rules: {
so
well, you could add your custom validation method using addMethod, like
$.validator.addMethod("regx", function(value, element, regexpr) {
return regexpr.test(value);
}, "Please enter a valid pasword.");
And ,
...
$("#myBlahForm").validate({
rules: {
somePassword: {
required: true ,
//change regexp to suit your needs
regx: /^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])\w{6,}$/,
minlength: 5,
maxlength: 8
}
}
required: function(element){
return /[a-zA-Z0-9]/.test($('#someConfirmPassword').val());
}
Above expression will return true if regexp passes, false if it doesn't. Change it to fit your needs.