JQuery验证抛出Uncaught SyntaxError:意外的数字

时间:2013-11-11 13:01:57

标签: jquery jquery-validate

我有一个使用jQuery Validate的验证函数,它当前给了我错误:

  

未捕获的SyntaxError:意外的数字

然而,我似乎无法找出我的代码到底出了什么问题。我已经尝试通过评论删除违规行,但我得到的只是另一个错误

  

未捕获的SyntaxError:意外的标识符

我的代码:

<script type="text/javascript">
    $(document).ready(function(){
        $.extend($.validator.messages,{
            equalTo: "Your passwords do not match.",
            remote: "The password you entered is incorrect."
        });

        $('#PasswordChange').validate(function() {
            rules: {
                ChangePassNew: {
                    required: true,
                    minlength: 6 //<-- the line giving the error.
                },
                ChangePassConfirmNew: { //<-- the line giving the new error once the offending line is commented out
                    required: true,
                    minlength: 6
                },
                ChangePassConfirmOld:{
                    required: true,
                    minlength: 6,
                    remote: "verifypass.php"
                },
                messages: {
                    ChangePassNew: {
                        required:"Please enter a password.",
                        minlength:"Please enter at least 6 characters."
                    },
                    ChangePassConfirmNew: {
                        required:"Please enter a password.",
                        minlength:"Please enter at least 6 characters."
                    },
                    ChangePassConfirmOld: {
                        required:"Please enter a password.",
                        minlength:"Please enter at least 6 characters.",
                        remote:"The password you entered is incorrect."
                    },
                },
            },
            submitHandler:function(form){
                form.submit();
            }
        });
    });
</script>

任何帮助都将不胜感激。

1 个答案:

答案 0 :(得分:2)

更改

$('#PasswordChange').validate(function(){

$('#PasswordChange').validate({

您需要一个包含选项的对象,而不是一个函数。