var b = false; $(function() { $("#userid").blur(function() { checkUseName($(this)); }); var checkUseName = function(obj) { var username = $.trim(obj.val()); if (!/^([0-9](?=[0-9]*?[a-zA-z])\w{4,12})|([a-zA-Z](?=[a-zA-Z]*?[0-9])\w{4,12})$/.test(username)) { obj.siblings("h4").show().html('格式不正确'); obj.parent().find("img").show().attr("src", "images/red_icon.png"); b = false; } else { obj.siblings("h4").hide(); obj.parent().find("img").show().attr("src", "images/g_icon.png"); b = true; } } $("#password1").blur(function() { checkPassword($(this)); }); var checkrealname = function(obj) { var checkrealname = $.trim(obj.val()); var reg1 = /^[\u4e00-\u9fa5]{2,4}$/; if (!reg1.test(checkrealname)) { obj.siblings("h4").show().html('格式不正确'); obj.parent().find("img").show().attr("on.png"); b = false; } else { obj.siblings("h4").hide(); obj.parent().find("img").show().attr("src", "images/g_icon.png"); b = true; } } $("#realname").blur(function() { checkrealname($(this)); }); var checktel = function(obj) { var checktel = $.trim(obj.val()); var reg2 = /^1[3,4,5,7,8]\d{9}$/; if (!reg2.test(checktel)) { obj.siblings("h4").show().html('格式不正确'); obj.parent().find("img").show().attr("src", "images/red_icon.png"); b = false; } else { obj.siblings("h4").hide(); obj.parent().find("img").show().attr("src", "images/g_icon.png"); b = true; } } $("#tel").blur(function() { checktel($(this)); }); var checkEmail=function(obj){ var email=$.trim(obj.val()); if(email==''){ obj.siblings("h4").show().html('邮箱不能为空'); obj.parent().find("img").show().attr("src", "images/red_icon.png"); b= false; } else if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(obj.val())) { obj.siblings("h4").show().html('邮箱格式不正确'); obj.parent().find("img").show().attr("src", "images/red_icon.png"); b= false; }else{ obj.siblings("h4").hide(); obj.parent().find("img").show().attr("src", "images/g_icon.png"); b = true; } } $("#email").blur(function(){checkEmail($(this))}); var checkPassword = function(obj) { var pwd = $.trim(obj.val()); if (!/^\w{6,15}$/.test(pwd)) { obj.siblings("h4").show().html('格式不正确'); obj.parent().find("img").show().attr("src", "images/red_icon.png"); b = false; } else { obj.siblings("h4").hide(); obj.parent().find("img").show().attr("src", "images/g_icon.png"); b = true; } } $("#confirmpassword1").blur(function() { checkConfirmPassword($(this)); }); var checkConfirmPassword = function(obj) { var confirmPwd = $.trim(obj.val()); if ($.trim($("#password1").val()) != '') { if ($("#password1").val() != confirmPwd) { obj.siblings("h4").show().html('两次不一样'); obj.parent().find("img").show().attr("src", "images/red_icon.png"); b = false; } else { obj.siblings("h4").hide(); obj.parent().find("img").show().attr("src", "images/g_icon.png"); b = true; } }else{ obj.siblings("h4").show().html('不能为空'); obj.parent().find("img").show().attr("src", "images/red_icon.png"); b = false; } } $("#question").blur(function() { checkQuestion($(this).find("option:selected")); }); var checkAnswer=function(obj){ var answer=$.trim(obj.val()); if(answer==''){ obj.siblings("h4").show().html('答案不能为空'); obj.parent().find("img").show().attr("src", "images/red_icon.png"); b= false; }else{ obj.siblings("h4").hide(); obj.parent().find("img").show().attr("src", "images/g_icon.png"); b = true; } } $("#answer").blur(function(){checkAnswer($(this))}); var checkQuestion = function(obj) { var qws = obj.val(); console.log(obj.val()); if (qws =='请选择密保问题') { obj.parent().siblings("h4").show().html('请选择密保问题'); b = false; obj.parent().find("img").show().attr("src", "images/red_icon.png"); } else { obj.siblings("h4").hide(); b = true; } } //点击获取验证码 var getcode = function(obj) { $(obj).prev().attr("src", "/getcode?r=" + Math.rand()); } $("#btnSubmit").click(function() { checkUseName($("#userid"));if(!b)return; checkPassword($("#password1"));if(!b)return; checkConfirmPassword($("#confirmpassword1"));if(!b)return; checkQuestion($("#question option:selected"));if(!b)return; checkAnswer($("#answer"));if(!b)return; checkrealname($("#realname"));if(!b)return; checktel($("#tel"));if(!b)return; checkEmail($("#email"));if(!b)return; if ($("#agree").attr("checked") != true) { $("#b_agree").show().find("span").html("如果您同意我们的条件和条款,且年满18岁,请勾选"); b = false; } if (b) { $.ajax({ type: 'POST', url: "/getcode", //url async: false, data: { code: $.trim($("#affiliatecode").val()) }, success: function(data) { b = data; //返回一个bool值 }, dataType: 'json' }); if (b) alert("提交"); } }); var checkLogin = { checkAccount: function(obj) { if ($.trim(obj.val()) == '') { $("#spanLogin_error").show().html('用户名不能为空'); return false; } return true; }, checkAccountPassword: function(obj) { if ($.trim(obj.val()) == '') { $("#spanLogin_error").show().html('密码不能为空'); return false; } return true; }, getcookies: function(name) { var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)"); if (arr = document.cookie.match(reg)) return unescape(arr[2]); else return null; }, setcookies: function(name, value) { var Days = 30; var exp = new Date(); exp.setTime(exp.getTime() + Days * 24 * 60 * 60 * 1000); document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString(); }, init: function() { if (this.getcookies("account")) $("#accountid").val(this.getcookies("account")); $("#accountid").blur(function() { checkLogin.checkAccount($(this)); }); $("#accpassword").blur(function() { checkLogin.checkAccountPassword($(this)); }); $("#Login").click(function() { if (checkLogin.checkAccount($("#accountid")) && checkLogin.checkAccountPassword($("#accpassword"))) { $('#popup_login_form').trigger('submit'); } }); } } checkLogin.init(); var findPwd = { checkUserName: function(obj) { var username = $.trim(obj.val()); if (username == '') { $("#spanLogin_error2").show().html('用户名不能为空'); return false; } else { $("#spanLogin_error2").hide(); return true; } }, checkCode1: function(obj) { var code = obj.val(); if (code == '') { $("#spanLogin_error2").show().html('验证码不能为空'); return false; } else { var c = false; $.ajax({ type: 'POST', url: "/getcode", //url async: false, data: { code: $.trim(obj.val()) }, success: function(data) { c = data; //返回一个bool值 if (!c) $("#spanLogin_error2").show().html('验证码不正确'); }, dataType: 'json' }); return c; } }, checkCode2: function(obj) { var code = obj.val(); if (code == '') { $("#spanLogin_error").show().html('验证码不能为空'); return false; } else { var c = false; $.ajax({ type: 'POST', url: "/getcode", //url async: false, data: { code: $.trim(obj.val()) }, success: function(data) { c = data; //返回一个bool值 if (!c) $("#spanLogin_error").show().html('验证码不正确'); }, dataType: 'json' }); return c; } }, newPassword: function(obj) { if ($.trim(obj.val()) == '') { obj.siblings("h4").show().html('密码不能为空'); obj.parent().find("img").show().attr("src", "images/red_icon.png"); return false; } else if (!/^\w{6,15}$/.test($.trim(obj.val()))) { obj.siblings("h4").show().html('密码格式不正确'); obj.parent().find("img").show().attr("src", "images/red_icon.png"); return false; } else { obj.parent().find("img").show().attr("src", "images/g_icon.png"); obj.siblings("h4").hide(); return true; } }, confirmNewPassword: function(obj) { if ($.trim(obj.val()) == '') { obj.siblings("h4").show().html('密码不能为空'); obj.parent().find("img").show().attr("src", "images/red_icon.png"); return false; } else if ($("#newpwd").val() != obj.val()) { obj.siblings("h4").show().html('两次密码不一致'); obj.parent().find("img").show().attr("src", "images/red_icon.png"); return false; } else { obj.parent().find("img").show().attr("src", "images/g_icon.png"); obj.siblings("h4").hide(); return true; } }, codeOrEmail: function(obj) { if ($.trim(obj.val()) == '') { obj.siblings("h4").show().html('验证码不能为空'); obj.parent().find("img").show().attr("src", "images/red_icon.png"); return false; } if ($(".chosefs label.on").attr("data-value") == 2) { if (!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(obj.val())) { obj.siblings("h4").show().html('邮箱格式不正确'); obj.parent().find("img").show().attr("src", "images/red_icon.png"); return false; } } else { obj.parent().find("img").show().attr("src", "images/g_icon.png"); obj.siblings("h4").hide(); return true; } }, init: function() { $("#sourceName").blur(function() { findPwd.checkUserName($(this)) }); $("#checkcode1").blur(function() { findPwd.checkCode1($(this)) }); $("#nextzh1").click(function() { if (findPwd.checkUserName($("#sourceName")) && findPwd.checkCode1($("#checkcode1"))) { //下一步 guanbi(); tanchu('#zhaohui2'); } else { //下一步 guanbi(); tanchu('#zhaohui2'); } }); $("#checkcode2").blur(function() { findPwd.checkCode2($(this)) }); $("#checkcode2").siblings("a").click(function() { $(this).prev().attr("src", "/getcode?r=" + Math.rand()); //获取验证码 }); $("#nextzh2").click(function() { if (findPwd.checkCode2($("#checkcode2"))) { //下一步 guanbi(); tanchu('#zhaohui3') } else { guanbi(); tanchu('#zhaohui3') } }); $("#newpwd").blur(function() { findPwd.newPassword($(this)); }); $("#confirmNewPwd").blur(function() { findPwd.confirmNewPassword($(this)); }); $("#checkcode3").blur(function() { findPwd.codeOrEmail($(this)); }); $("#prevbtn").click(function() { if (findPwd.newPassword($("#newpwd")) && findPwd.confirmNewPassword($("#confirmNewPwd")) && findPwd.codeOrEmail($("#checkcode3"))) { $.post("/editpwd", { pwd: $("#newpwd").val(), confirmpwd: $("#confirmNewPwd").val(), code: $("#checkcode3").val() }, function(data) { if (data) //返回bool alert("修改成功"); else alert("修改失败"); }); } }); $("#nextbtn").click(function() { $.post("/sendcode", {}, function(data) { if (data) //返回bool类型 alert("发送成功"); else alert("发送失败"); }); }); } } findPwd.init(); });