2010-03-08 95 views
0

我正在使用jQuery的验证插件: http://docs.jquery.com/Plugins/Validation如何免除要验证的元素?

我想知道如何豁免一个字段进行验证?目前表单中的所有字段都会自动检查。


我不知道这是否会因为我想免除不包括(显然:))元素有助于

$("#contactForm").validate({ 
     rules: { 
         first_name:{required: true,charsonly:true,minlength: 1 }, 
         last_name:{required:true,charsonly:true,minlength: 1 }, 
         birthday:{required:true,min:1,max:31 }, 
         birthmonth:"required", 
         birthyear:"required", 
         username: {required: true,minlength:1,maxlength:32,username:true,notChinese:true,noSpecial:true}, 
         password1:{required:true,minlength: 5,maxlength: 10, alphaNum: true }, 
         password2:{required:true,minlength: 5,maxlength: 10, alphaNum: true, equalTo: "#password1"}, 
         currency:"required", 
         address:{required: true,noSpecial:true,minlength:2}, 
         city:{required: true,noSpecial:true,minlength:2}, 
         state:{noSpecial:true}, 
         countrycode:"required", 
         zip:{required:true,zipTest:true}, 
         email:{required:true,email: true}, 
         confirmemail:{required: true,equalTo: "#email",email:true}, 
         phone:{required: true,minlength:6,maxlength:20,phoneUS:true}, 
         cellphone:{required: true,minlength:6,maxlength:20,phoneUS:true}, 
         custom06:{acceptIM:true} 

     } }); 

发现了它。 我使用了忽略验证方法。


这里的

$("#myform").validate({ 
    ignore: ".ignore" 
}) 
+0

只是为了澄清任何信息领域。我想要做的就是删除这个插件,即使没有对该元素进行验证,该插件也会自动附加这段代码。 – wnoveno 2010-03-08 07:02:14

+0

看来问题源于使用全局规则函数而不是设置每个元素的类。我仍然不知道如何解决这个问题。 – wnoveno 2010-03-08 07:55:00

回答

0

您正在使用某种形式的服务器端技术的代码?验证库需要设置规则,如果您严格按照javaScript(jQuery)进行操作,那么它是手动的。

UPDATE:您可以删除规则有以下:http://docs.jquery.com/Plugins/Validation/rules#.22remove.22rules

发生在身体的末端以下。

$("selector").rules("remove"); 
+0

不。并且我想豁免的领域不在规则中(这意味着我没有添加任何内容,因为我不想验证它)。 – wnoveno 2010-03-08 06:41:39

+0

请粘贴你的源代码。 – 2010-03-08 06:55:01

0

它取决于类属性。见例子:

此为必填字段和电子邮件的格式:它不能为空

input class="required email" 

此字段不是必需的,电子邮件的格式:它可以为空

input class="email" 

此字段不需要和没有格式:它可以是空的

input class="" 
+0

这不起作用,因为我已将图像添加到插件附加到每个元素(x或检查)的标签上。 – wnoveno 2010-03-08 07:01:22

+0

让我们看看完整的代码。 – Sergei 2010-03-08 07:52:50

0

您可以设置自己的消息:

$("#contactForm").validate({ 
     rules: { 
     input1: required, 
     input2: required, 
     no-validation: required, 
     input4: required, 
     }, 
     messages: { 
     no-validation: '' 
     } 
}); 

只要把一个空字符串为您不想将显示..