jquery仅验证数字

发布于 2024-09-14 00:37:33 字数 255 浏览 1 评论 0 原文

我有 jquery.validate.js 插件,它对我来说工作得很好。

我的问题是:

我有一个文本框,这个文本框是强制性的,应该只接受数字。

在js中,我可以看到有数字验证,问题是我不知道如何使用它。

我只知道如何通过放入文本框字段 来创建必填字段

那么,如何添加一个验证标准以仅接受数字。

谢谢

I am having the jquery.validate.js plugin and it is working fine for me.

My question is :

I am having a textbox and this textbox is mandatory and should only accept digits.

In the js, I can see that there is validation for the digits and the problem is that I do not know how to use it.

I only knew how to make the field required by putting in the textbox field <class="required">

So, how can I add one more validation criteria to accept only digits.

Thanx

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无可置疑 2024-09-21 00:37:33

要检查它,请添加

$("#myform").validate({
  rules: {
    amount: {
      required: true,
      digits: true
    }
  }
});

http://docs.jquery.com/Plugins/Validation/Methods/digits

to check it add

$("#myform").validate({
  rules: {
    amount: {
      required: true,
      digits: true
    }
  }
});

http://docs.jquery.com/Plugins/Validation/Methods/digits

深爱不及久伴 2024-09-21 00:37:33
$("#mobile_number").validate({
            rules: {

                mobile_number: {required: true,number:true}
            },
            messages: {
                mobile_number: {required: "Please Enter Your Mobile Number",number:"Please enter numbers Only"}
            }

 });
$("#mobile_number").validate({
            rules: {

                mobile_number: {required: true,number:true}
            },
            messages: {
                mobile_number: {required: "Please Enter Your Mobile Number",number:"Please enter numbers Only"}
            }

 });
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文