jquery.validate ajax方式验证

在做网站的时候有一块需要用到jquery.validate插件 ajax方式的方式来验证原始密码是否正确,研究了研究加上博客园朋友的帮助,终于实现了。贴出代码

<script type="text/javascript">
    $(function () {
        $("#form1").validate({
            rules: {
                pwd: {
                    required: true,
                    remote: {
                        url: "@Url.Action("ValidatePwd", "UserInfo")",
                        type: "post",
                        dataType: "json",
                        data: {
                            pwd: function () {
                                return $("#pwd").val();    //这个是取要验证的密码
                            }
                        },
                        dataFilter: function (data) {    //判断控制器返回的内容
                            if (data == "true") {
                                return true;
                            }
                            else {
                                return false;
                            }
                        }
                    }
                },
                password: {
                    required: true,
                    rangelength: [6, 16]
                },
                confirm_password: {
                    required: true,
                    rangelength: [6, 16],
                    equalTo: "#password"
                }
            },
            messages: {
                pwd: {
                    required: "请填写原始密码!",
                    remote: "原始密码不正确,请重新填写!"    //这个地方如果不写的话,是自带的提示内容,加上就是这个内容。
                },
                password: {
                    required: "请填写新密码",
                    minlength: jQuery.format("登录名长度在6-12位之间!")
                },
                confirm_password: {
                    required: "请填写确认密码!",
                    minlength: "密码需由6-16个字符(数字、字母、下划线)组成!",
                    equalTo: "两次输入密码不一致!"
                }
            },
            onfocus: true,    
            onkeyup: false,    //这个地方要注意,修改去控制器验证的事件。
            onsubmit: false
        });

jquery.validate ajax方式验证,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。