, ,
:
, , :
function mytest(value, element, params){...}
, , jQuery Validation. addMethod() validator.
:
$(document).ready(function() {
$.validator.addMethod(
"passwd",
function(value, element, regexp) {
var re = new RegExp(regexp);
return this.optional(element) || re.test(value);
},
"Invalid input"
);
$("#add_user_form").validate({
rules:{
user_name: {
required: true,
minlength: 5,
maxlength: 15,
noSpace: true
},
password: {
required: true,
minlength: 8,
passwd: "((?=(.*\\d.*){2,})(?=(.*[a-zA-Z].*){2,})(?=(.*[@#$(){}!~,.!^?/|+=-_%].*){2,}).{8,20})"
}
},
messages:{
user_name: {
required: "*",
minlength: " at least 5 characters",
maxlenght: " only 15 characters",
noSpace: " No space Please"
},
password: {
required: "*",
minlength: " Your password must be at least 8 characters long",
passwd: " Invalid Password choice"
}
});
good links:
Starting with jQuery - How to write custom validation rules
How to add a rule to validate an expression?
source
share