I want besides the numbers to put a letter "p" which is supported by validator. But I do not understand why the end is placed the "Letters only please");... This is a validator for a price field and lets only numbers to input and I want to put the letter "p" to be accepted. Here is my Jquery code, maybe this can help:
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 !
what you want? put a example a match. you want a match like this? 895p
jQuery.validator.addMethod("priceonly", function(value, element) {
return this.optional(element) || /^[0-9\,]+p$/i.test(value);
}, "Letters only please");
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.