使用jquery验证忽略字段文件

ignore Field File with jquery validation

本文关键字:字段 文件 jquery 验证 使用      更新时间:2023-09-26

这是我的表单和验证jQuery,但在UI中,它在文件上传(倍数)中显示了"输入不超过3个字符。"。我认为问题是文件字段中的属性maxlength="3"

如何删除此字段的验证?

        <table cellpadding="0" cellspacing="0" class="main_table">
                <tr>
                    <td class="label">@Resources.Registo.nome</td>
                    <td>@Html.TextBox("FullName", (Model != null ? Model.FullName : string.Empty), new { @class = "width250" })
                        @Html.ValidationMessageFor(model => model.FullName)</td>
                </tr>
                <tr>
                    <td class="label">@Resources.Registo.email</td>
                    <td>@Html.TextBox("Email", (Model != null ? Model.Email : string.Empty), new { @class = "width250" })
                        @Html.ValidationMessageFor(model => model.Email)</td>
                </tr>
                <tr>
                    <td class="label">@Resources.Registo.exemploFotos</td>
                    <td><input type="file" name="fileUpload" class="multi" accept="jpeg|jpg" maxlength="3" /></td>
                </tr>
                <tr><td colspan="2"><a class="button" onclick="$('#FormToValidate').valid() == true ? get_form(this).submit() : false" id="validateAndSubmitBtn" ><span>@Resources.Global.btnSubmit</span></a></td></tr>
         </table>

$().ready(function () {
        // validate signup form on keyup and submit
        $("#FormToValidate").validate({
            rules: {
                FullName: {
                    required: true
                },
                Email: {
                    required: true,
                    email: true
                }
            },
            messages: {
                FullName: {
                    required: "@Resources.Registo.requiredFullName"
                },
                Email: {
                    required: "@Resources.Registo.requiredEmail",
                    email: "@Resources.Registo.emailValid"
                }
            }
        });
    });

尝试ignore参数:

$("#FormToValidate").validate({
    rules: {
        FullName: {
            required: true
        },
        Email: {
            required: true,
            email: true
        }
    },
    messages: {
        FullName: {
            required: "@Resources.Registo.requiredFullName"
        },
        Email: {
            required: "@Resources.Registo.requiredEmail",
            email: "@Resources.Registo.emailValid"
        }
    },
    ignore: "input[type='file']"
});

如果您愿意,可以为参数使用任何有效的jQuery选择器。