Jquery Validate插件中的几个自定义验证规则 [英] Several custom validate rules in Jquery Validate plugin

查看:254
本文介绍了Jquery Validate插件中的几个自定义验证规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jquery Validate插件检查用户输入

I am using Jquery Validate plugin to check the user input

但是,我发现该选项不够用,因此我决定使用自定义规则

however, i found that the option is not sufficient and i decided to use custom rules

有没有网站提供这些规则?

Are there any website provide those rules?

我要检查的是日期格式仅整数

谢谢

推荐答案

您可以通过扩展jquery验证器

you can add custom rules by extending the jquery validator

   jQuery.validator.addMethod("customdate", function(value, element) { 
   return this.optional(element) || {your rules}
     }, "eg YYYY-MM-DD");

在此处查看

http://docs.jquery.com/Plugins/Validation/Validator/addMethod#namemethodmessage

仅用于数字,您无需编写自己的规则.它已经包含功能,尝试数字和数字

For number only, you don't need to write your own rules.It already include the feature,try digits and number

  1  $("#form").validate({
        rules:{
            inputtype:{required:true,digits:true}

        },
        messages:{
            inputtype:{required:"Please provide Number",digits,"Number Only!"}

        }
    });

    2.  $("#form").validate({
        rules:{
            inputtype:{required:true,number:true}

        },
        messages:{
            inputtype:{required:"Please provide Number",number,"Number Only!"}

        }
    });

这篇关于Jquery Validate插件中的几个自定义验证规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆