简体   繁体   English

jQuery:插件验证,如何验证十几个不同的字段?

[英]jQuery: Plugin Validation, how do I validate a dozen or so different fields?

I'm using this: http://docs.jquery.com/Plugins/Validation/Methods/accept#extension 我正在使用这个: http : //docs.jquery.com/Plugins/Validation/Methods/accept#extension

I'm trying to alert the user to only upload PNGs, Jpgs, JPEGS and PDFs. 我正在尝试提醒用户仅上传PNG,Jpg,JPEG和PDF。 On the server end if they do attempt, it will not work. 在服务器端,如果他们尝试尝试,它将无法正常工作。 On the user end I want to alert them what they are doing is false. 在用户端,我想提醒他们他们在做什么是错误的。 Try a different file type. 尝试使用其他文件类型。 Maybe even prevent them from submitting the form. 甚至可能阻止他们提交表单。

How do I get this to work with 1 dozen file fields? 如何使它与1打文件字段一起使用?

code: 码:

$("#fileForm").validate({
          rules: {
            yourFileFieldNameHere: {
              required: false,
              accept: "png,jpg,jpeg,pdf"
            }
          }
        });

I'm assuming the yourFileFieldNameHere is the "name=" of the input field as thats the only parameter that works. 我假设yourFileFieldNameHere是输入字段的“ name =”,因为那是唯一起作用的参数。 I've tried to use the ID name. 我尝试使用ID名称。

Any suggestions? 有什么建议么?

Revised the answer, i missed the info about a dozen fields. 修改了答案,我错过了有关十几个领域的信息。 Try adding a rule for the dozen fields like this: 尝试为十几个字段添加规则,如下所示:

    $("#fileForm").validate({
              rules: {
                //any other rules go here
              }
            });

$('.your-dozen-fields-selector').rules("add", {
 required: false,
 accept: "png,jpg,jpeg,pdf"
});

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

相关问题 如何使用jQuery验证插件验证字段 - how validate fields using jquery validation plugin 我如何使用jquery验证插件进行条件验证 - how do i use the jquery validation plugin to conditional validate 如何使用jquery验证插件验证名称中带点的输入字段? - How to validate input fields with a dot in name using the jquery validation plugin? 如何仅验证jQuery验证插件中的必填字段? - How to validate only mandatory fields in jQuery validation plugin? .Validate jQuery Validation插件不忽略隐藏字段 - .Validate jQuery Validation Plugin not Ignoring Hidden Fields 如何使用此jQuery Pluggin验证不同类型的输入/字段? - How Can I validate different types of inputs/fields with this jQuery Pluggin? 如何使用jQuery验证插件来验证字符串集合? - How do I use jQuery validation plugin to validation a collection of strings? 如何使用jquery验证插件显示不同的错误消息 - How do I display different error messages using jquery validation plugin 如何使用jquery验证动态填充的表单字段? - How do I use jquery to validate form fields, that was populated dynamically? 如何通过jquery验证插件实现我的验证? 我无法验证我的表格吗? - How to implement my validation, through jquery validation plugin? I am not able to validate my form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM