除了数字之外我还想写一封信" p"验证者支持。但是我不明白为什么最终会被放置在" Letters only please"); ... 这是价格字段的验证器,只允许输入数字,我想把字母" p"被接受。 这是我的Jquery代码,也许这可以帮助:
jQuery('#dtf-form-backend').validate({
rules: {
contactName: {
required: true,
lettersonly: true
},
contactEmail: {
required: true,
email: true
},
catId: {
required: true
},
price: {
required: false,
priceonly: false
}
},
messages: {
contactName: {
required: "Please enter your name",
lettersonly: "No numbers or special symbols"
},
contactEmail: {
required: "Email is required",
email: "Please enter a valid email"
},
catId: {
required: "Please choose category"
},
price: {
required: "Please specify item price",
priceonly: "Only number is accepted"
}
}
});
jQuery.validator.addMethod("priceonly", function(value, element) {
return this.optional(element) || /^[0-9\,]+$/i.test(value);
}, "Letters only please");
Thx Elod!
答案 0 :(得分:0)
jQuery.validator.addMethod("priceonly", function(value, element) {
return this.optional(element) || /^[0-9\,]+p$/i.test(value);
}, "Letters only please");