You can use the pattern rule to pass a custom regex pattern like
$("#myform").validate({
//for debug only
debug: true,
rules: {
field: {
required: true,
pattern: /^(d+|d+,d{1,2})$/
}
},
messages: {
field: {
pattern: 'Please use the proper pattern'
}
}
});
Demo: Fiddle
If it is a repeated pattern create a custom validation rule
jQuery.validator.addMethod("mynumber", function (value, element) {
return this.optional(element) || /^(d+|d+,d{1,2})$/.test(value);
}, "Please specify the correct number format");
$("#myform").validate({
//for debug only
debug: true,
rules: {
field: {
required: true,
mynumber: true
}
}
});
Demo: Fiddle
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…