简体   繁体   English

jQuery验证功能不起作用

[英]jQuery Validate function not working

This problem, i am sure is very trivial but i am not able to get past it. 这个问题,我敢肯定是微不足道的,但我无法克服。

My form is not getting validated using jquery validate. 我的表单未使用jquery validate进行验证。

        $(document).ready(function () {
            $("#loginForm").validate({
                rules: {
                    email: "required",
                    passwd: "required",
                    email:{
                        minlength: 10
                    }
                },
                messages: {
                    email: "Please enter your email",
                    passwd: "Please enter your passwd",
                    email:{
                        minlength: "Minlength has to be 10"
                    }
                },

                submitHandler: function(form) {
                    $("#pp").text("right");
                    form.submit();
                }
            }); 
        })  

No console errors. 没有控制台错误。 I have following 我有以下

name, passwd are name, id of the fields i am trying to validate and loginForm is id of form. name,passwd是名称,我要验证的字段的ID,loginForm是表单的ID。 The problem is i don't see the error messages when i pass invalid input. 问题是我通过无效输入时看不到错误消息。 Going through debug mode, i don't see the stack reaching inside validate function ever although an alert inside ready function before validate is called. 经历调试模式,尽管调用了validate之前ready函数内部的警报,但我从未看到堆栈到达validate函数内部。

You did not show your HTML markup, so this answer assumes you correctly named your input elements. 您没有显示HTML标记,因此此答案假定您正确命名了input元素。

In your code, you're specifying email twice... 在您的代码中,您两次指定了email ...

rules: {
    email: "required",
    passwd: "required",
    email:{  // <- duplicate
        minlength: 10
    }
},

If you need to specify multiple rules for one field, then specify the field once and list the rules inside... 如果您需要为一个字段中指定多个规则,然后指定字段一次 ,并列出里面的规则...

rules: {
    email: {
        required: true,
        minlength: 10
    },
    passwd: "required"
},

Your messages option has the same problem. 您的messages选项有相同的问题。

Working DEMO: http://jsfiddle.net/4937t/ 工作演示: http//jsfiddle.net/4937t/

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM