登陆页面的验证js

这是我的js没有什么特别的  想保存下来而已微笑

$(document).ready(function () {
    $(".invite").hide();
    $(".tk_ok").hide();
    //这里全是验证
    $("#input_number").blur(function () {
        $(this).css("background-color", "#f5f5f5");
        $(".yz_number .fault").remove();
        var p1 = /^(?:13\d|15\d|18\d|17\d|16\d)\d{5}(\d{3}|\*{3})$/;
        if (!p1.test(this.value)) {
            $(".yz_number").append("<span class='linkRight fault'>请输入正确的手机号码</span>");
            $(".btn_yz").css("background-color", "#8d8f8e");
            $(this).css("border", "1px red solid")
            //$("#button-zc").attr({ "disabled": true });
            //$("#button-dl").attr({ "disabled": true });
        }
        else {
            $(this).css("border", "1px #999 solid");
            if ($("#code").text() == "获取验证码" || $("#code").text() == "重新获取验证码")
                $(".btn_yz").css("background-color", "#11a8ef");
        }
        $(".yz_number .p_little").remove();
    })
    $("#input_number").focus(function () {
        $(".yz_number").append("<p class='p_little'>手机号码</p>");
        $(".yz_number .fault").remove();
        $(this).css("border", "1px #11a8ef solid");
        $(this).css("background-color", "white");
        //$("#button-zc").attr({ "disabled": false });
        //$("#button-dl").attr({ "disabled": false });
    })
    //测试用
    $("#input_yzm").blur(function () {
        $(this).css("background-color", "#f5f5f5");
        $(".yz_yzm .p_little").remove();
        $(".yz_yzm .fault").remove();
        if (localStorage.code) {
            if (this.value.trim() != localStorage.code) {
                $(".yz_yzm").append("<span class='linkRight fault'>手机验证码输入错误</span>");
                $(this).css("border", "1px red solid");
            }
            else {
                $(this).css("border", "1px #999 solid");
            }
        }
        else {
            $(".yz_yzm").append("<span class='linkRight fault'>请输入手机验证码</span>");
            $(this).css("border", "1px red solid");
        }
    });
    $("#input_yzm").focus(function () {
        $(".yz_yzm .fault").remove();
        //$("#button-zc").attr({ "disabled": false });
        $(".yz_yzm").append("<p class='p_little'>验证码</p>");
        $(this).css("border", "1px #11a8ef solid");
        $(this).css("background-color", "white");
    })

    $("#input_password").blur(function () {
        $(this).css("background-color", "#f5f5f5");
        $(".yz_password .fault").remove();
        if (this.value.trim().length < 6) {
            $(this).css("border", "1px red solid");
            $(".yz_password").append("<span class='linkRight fault'>请输入至少6位的密码</span>");
            //$("#button-zc").attr({ "disabled": true });
            //$("#button-dl").attr({ "disabled": true });
        }
        else {
            $(this).css("border", "1px #999 solid");
        }
        $(".yz_password .p_little").remove();
    })
    $("#input_password").focus(function () {
        $(".yz_password").append("<p class='p_little'>密码</p>");
        $(".yz_password .fault").remove();
        $(this).css("border", "1px #11a8ef solid");
        $(this).css("background-color", "white");
        //$("#button-zc").attr({ "disabled": false });
        //$("#button-dl").attr({ "disabled": false });
    })
    $("#input_qrpassword").blur(function () {
        $(this).css("background-color", "#f5f5f5");
        $(".yz_qrpassword  .fault").remove();
        $(".yz_qrpassword .p_little").remove();
        var x = $("#input_password").val();
        if (this.value.trim() == "" || this.value.trim() == "确认密码") {
            $(this).css("border", "1px red solid");
            $(".yz_qrpassword").append("<span class='linkRight fault'>请再次输入密码</span>");
            //$("#button-zc").attr({ "disabled": true });
        }
        else if (this.value != x) {
            $(this).css("border", "1px red solid");
            $(".yz_qrpassword").append("<span class='linkRight fault'>两次密码不一致</span>");
            //$("#button-zc").attr({ "disabled": true });
        }
        else {
            $(this).css("border", "1px #999 solid");
        }
    })
    $("#input_qrpassword").focus(function () {
        $(".yz_qrpassword").append("<p class='p_little'>确认密码</p>");
        $(".yz_qrpassword  .fault").remove();
        $(this).css("border", "1px #11a8ef solid");
        $(this).css("background-color", "white");
        //$("#button-zc").attr({ "disabled": false });
    })
    $("#input-yqm").blur(function () {
        $(this).css("background-color", "#f5f5f5");
        $(".yz_yqm .fault").remove();
        if (this.value == null || this.value == " " || this.value == "输入邀请码") {
            $(this).css("border", "1px red solid");
            $(".yz_yqm").append("<span class='p_little linkRight fault'>请输入邀请码</span>");
            //$(".btn_ok").attr({ "disabled": true });
        }
        else {
            $(this).css("border", "1px #11a8ef solid");
        }
    })
    $("#input-yqm").focus(function () {
        //$(".btn_ok").attr({ "disabled": false });
        $(".yz_yqm .fault").remove("fast");
        $(this).css("border", "1px #11a8ef solid");
        $(this).css("background-color", "white");
    })
    //邀请码完成后注册
    $("#btn_ok").click(function () {
        $(".zc_ok").slideDown("fast");
        $("#input-yqm").blur();
        if ($(".fault").html() != null)
            return;
        else {
            register();
        }
    })
    //注册POST提交,无邀请码
    $("#btn_noinvi").click(function () {
        $(".tk_ok").slideDown();
        register();
    })
    //同意协议
    $("#cb_agree").click(function () {
        $(".yz_agree .fault").remove();
        var s = $("#cb_agree").attr("checked");
        if (s != "checked") {
            $(".yz_agree").append("<span class='linkRight fault'>*</span>");
            return;
        }
        //else
        //$("#button-zc").attr({ "disabled": false });
    })
    //点击注册后验证
    $("#button-zc").click(function () {
        $("#input_number").blur();
        $("#input_yzm").blur();
        $("#input_password").blur();
        $("#input_qrpassword").blur();
        var s = $("#cb_agree").attr("checked");
        if (s != "checked") {
            $(".yz_agree .fault").remove();
            $(".yz_agree").append("<span class='linkRight fault'>*</span>");
            //$(this).attr({ "disabled": true });
        }
        if ($(".fault").html() != null)
            return;
        else {
            localStorage.clear();
            yzm();
        }
    })
    //点击登陆后验证
    $("#button-dl").click(function () {
        $("#input_password").blur();
        $("#input_number").blur();
        if ($(".fault").html() != null)
            return;
        else
            login();
    })
    //登陆post提交
    function login() {
        var username = $("#input_number").val();
        var password = $("#input_password").val();
        $.post("/User/Login", { UserName: username, UserPassword: password }, function (data) {
            if (data.message == "登录成功")
                localStorage.UserName = username;
        });
    }
    //注册post提交
    function register() {
        var username = $("#input_number").val();
        var password = $("#input_password").val();
        var code = $("#input_yzm").val();
        var reuserpassword = $("#input_qrpassword").val();
        localStorage.clear();
        $.post("/User/Register", { UserName: username, Code: code, UserPassword: password, reUserPassword: reuserpassword }, function (data) {
            if (date.stateCode == "ok") {
                alert(data.msg);
                //if (data.AbsolutePath == "1") {
                //    //订单提交页面(余额不足需要充值,未登录)
                //} else if (data.AbsolutePath == "2") {

                //} else {

                //}
            } else {
                alert(data.msg)
            }
        });
    }

    function yzm() {
        $(".invite").slideDown();
    }
    //发送验证码事件
    //获取验证码
    var InterValObj2; //timer,控制时间
    var count2 = 60; //60 秒
    var curCount2;//当前剩余秒数
    $("#code").click(function () {
        $("#input_number").blur();
        if ($(".yz_number .fault").html() != null)
            return;
        curCount2 = count2;
        //设置button效果,开始计时
        $(".btn_yz").css("background-color", "#8d8f8e");
        //$("#code").css("ba");
        $("#code").text("(" + curCount2 + ")秒后重新获取");
        InterValObj2 = window.setInterval(SetRemainT, 1000); //启动计时器,1秒执行一次
        //向后台发送处理数据
        var username = $("#input_number").val();
        $.post("/User/getCode", { "UserName": username }, function (text) {
            if (text == "Error") {
                alert("发送失败");
            } else {
                alert("发送成功");
                alert(text);
                localStorage.code = text;
            }
        }, "html");
    });
    //timer处理函数
    function SetRemainT() {
        if (curCount2 == 0) {
            window.clearInterval(InterValObj2);//停止计时器
            $("#code").attr("onclick", "gCode()");//启用按钮
            $("#code").text("重新发送验证码");
            $(".btn_yz").css("background-color", "#11a8ef");
        }
        else {
            curCount2--;
            $("#code").text("(" + curCount2 + ")秒后重新获取");
        }
    }
    //重置密码
    $("#button-reset").click(function () {
        $("#input_number").blur();
        $("#input_yzm").blur();
        $("#input_password").blur();
        $("#input_qrpassword").blur();
        var s = $("#cb_agree").attr("checked");
        if ($(".fault").html() != null)
            return;
        else {
            localStorage.clear();
            var username = $("#input_number").val();
            var password = $("#input_password").val();
            var code = $("#input_yzm").val();
            var reuserpassword = $("#input_qrpassword").val();
            $.post("/User/ResetPassword", { UserName: username, Code: code, UserPassword: password, reUserPassword: reuserpassword });
        }
    })
    //验证旧密码
    $("#input_oldpassword").blur(function () {
        $(this).css("background-color", "#f5f5f5");
        $(".yz_oldpassword .fault").remove();
        if (this.value.trim() == null || this.value.trim() == "" || this.value.trim() == "原密码") {
            $(this).css("border", "1px red solid");
            $(".yz_oldpassword").append("<span class='linkRight fault'>请输入原密码</span>");
            //$("#button-zc").attr({ "disabled": true });
            //$("#button-dl").attr({ "disabled": true });
        }
        else {
            $(this).css("border", "1px #999 solid");
        }
        $(".yz_oldpassword .p_little").remove();
    });
    $("#input_oldpassword").focus(function () {
        $(".yz_oldpassword").append("<p class='p_little'>原密码</p>");
        $(".yz_oldpassword .fault").remove();
        $(this).css("border", "1px #11a8ef solid");
        $(this).css("background-color", "white");
    })
    //修改密码setnewpassword
    $("#button_setnewspassword").click(function () {
        $("#input_oldpassword").blur();
        $("#input_password").blur();
        $("#input_qrpassword").blur();
        if ($(".fault").html() != null)
            return;
        var oldpassword = $("#input_oldpassword").val();
        var newpassword = $("#input_password").val();
        var reuserpassword = $("#input_qrpassword").val();
        $.post("/User/SetNewPassword", { OldPassWord: oldpassword, NewPassWord: newpassword, reUserPassword: reuserpassword })
    })
})


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值