使用JQuery Validation Plugin验证<input type =“file”/>

时间:2013-05-23 09:21:13

标签: jquery

我使用JQuery Validation Plugin来验证我的表单,它适用于所有字段,
但是当我尝试将它用于<input type="file" id="ProjectInformation">

<script>
    $(function() {
        $("#feedback-form").validate({
            submitHandler: function(form) {
                form.submit();
            },
            rules: {
                Name: {
                    required: true,
                    minlength: 2
                },
                ProjectInformation: {
                    extension: "doc,txt,pdf",
                }
            },
            messages: {
                Name: {
                    required: "Please enter a name",
                    minlength: "Name must consist of at least 2 characters"
                },
                ProjectInformation: {
                    extension: "Only .doc, .txt, and .pdf files allowed",
                }
            }
        });
    });
</script>

我收到错误未捕获TypeError:无法调用未定义的方法'call'
怎么了?

1 个答案:

答案 0 :(得分:0)

我在验证插件中查了extension,发现在该示例中他们使用|代替,所以 尝试使用..

extension: "doc|txt|pdf",