Ive found some posts when people have specified how to add a method to the jquery validator, but Im getting an error. Below is my code:
// Validation
$(function () {
// Validation
$.validator.addMethod("checklower", function (value) {
return /[a-z]/.test(value);
});
$.validator.addMethod("checkupper", function (value) {
return /[A-Z]/.test(value);
});
$.validator.addMethod("checkdigit", function (value) {
return /[0-9]/.test(value);
});
$.validator.addMethod("pwcheck", function (value) {
return /^[A-Za-z0-9\d=!\-@._*]*$/.test(value) && /[a-z]/.test(value) && /\d/.test(value) && /[A-Z]/.test(value);
});
$("#smart-form-register").validate({
// Rules for form validation
rules: {
email: {
required: true,
email: true
},
emailConfirm: {
required: true,
email: true,
equalTo: '#email'
},
password: {
required: true,
minlength: 4,
maxlength: 20,
checklower: true,
checkupper: true,
checkdigit: true
},
passwordConfirm: {
required: true,
minlength: 4,
maxlength: 20,
equalTo: '#password'
},
firstname: {
required: true
},
lastname: {
required: true
},
gender: {
required: false
},
DOB: {
required: true
},
SelectedBU: {
required: true
},
terms: {
required: false
}
},
// Messages for form validation
messages: {
email: {
required: 'Please enter your email address',
email: 'Please enter a VALID email address'
},
emailConfirm: {
required: 'Please enter your email address one more time',
email: 'Please enter a VALID email address',
equalTo: 'Please enter the same email address as above'
},
password: {
required: 'Please enter your password',
pwcheck: 'Check that your password works',
checklower: "Need atleast 1 lowercase alphabet",
checkupper: "Need atleast 1 uppercase alphabet",
checkdigit: "Need atleast 1 digit"
},
passwordConfirm: {
required: 'Please enter your password one more time',
equalTo: 'Please enter the same password as above'
},
birthdate: {
required: 'Please select a birth date',
},
SelectedBU: {
required: 'Please select a business unit',
},
terms: {
required: 'You must agree with Terms and Conditions'
}
},
// Do not change code below
errorPlacement: function (error, element) {
error.insertAfter(element.parent());
}
});
});
But I am getting the following error:
Parser Error Message: "." is not valid at the start of a code block. Only identifiers, keywords, comments, "(" and "{" are valid.
Line 154: });
Line 155: $.validator.addMethod("pwcheck", function (value) {
Line 156: return /^[A-Za-z0-9\d=!-@._]$/.test(value) && /[a-z]/.test(value) && /\d/.test(value) && /[A-Z]/.test(value);
Line 157: });
Everything else works, except for the addition password checking.
Please can someone point out where and what I might be doing wrong, as Ive seen a post where the above checklower: true,checkupper: true, checkdigit: true
was marked as the answer, so my assumption is that it should work, but mine is not :(
Thanks for help in advance.