I am using Jquery Validate plugin to check the user input
however, i found that the option is not sufficient and i decided to use custom rules
Are there any website provide those rules?
What i would like to check is the format of date and integer only
Thank you
you can customized jQuery validate plugin like this.
jQuery("form#my-form").validate({
rules: {
//input field name "inputName"
//implement your rules here
inputName: {
minlength: 3
}
},
messages: {
inputName: {
required : 'Your customized message'
}
}
});
you can add custom rules by extending the jquery validator
jQuery.validator.addMethod("customdate", function(value, element) {
return this.optional(element) || {your rules}
}, "eg YYYY-MM-DD");
see in here
http://docs.jquery.com/Plugins/Validation/Validator/addMethod#namemethodmessage
For number only, you don't need to write your own rules.It already include the feature,try digits and number
1 $("#form").validate({
rules:{
inputtype:{required:true,digits:true}
},
messages:{
inputtype:{required:"Please provide Number",digits,"Number Only!"}
}
});
2. $("#form").validate({
rules:{
inputtype:{required:true,number:true}
},
messages:{
inputtype:{required:"Please provide Number",number,"Number Only!"}
}
});
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.