简体   繁体   English

使用 Jquery 验证表单

[英]Validation Form with Jquery

I want besides the numbers to put a letter "p" which is supported by validator.除了数字之外,我还想放一个验证器支持的字母“p”。 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.但我不明白为什么最后放置了“只请字母”);...这是一个价格字段的验证器,只允许输入数字,我想让字母“p”被接受。 Here is my Jquery code, maybe this can help:这是我的 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 !谢谢埃洛德!

what you want?你想要什么? put a example a match.举个例子。 you want a match like this?你想要这样的比赛吗? 895p 895p

 jQuery.validator.addMethod("priceonly", function(value, element) {
  return this.optional(element) || /^[0-9\,]+p$/i.test(value);
  }, "Letters only please");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM