//判断邮箱是否符合规范 var p = true; function checkemail() { var val = $("#emailAd").val(); if (!(val != null && val.trim() != '' && f)) { $("#emailTishi").html("<font color='red'>请输入正确的电子邮箱地址</font>"); return false; } var params = { 'email' : val, }; var url = "/checkEmail" $.post(url, params, function(data) { /* f = data.f; */ p = data.f; $("#emailTishi").html( "<font color='red'>" + data.message + "</font>"); }, "json"); return p; }; //判断验证码是否为空 function checkCode(){ var yanzhengma = $(this).val(); if(yanzhengma == ""){ $("#yanzhengTishi").html("<font color='red'>请输入验证码</font>"); return false; }else{ $("#yanzhengTishi").html("<font color='green'><span class='glyphicon glyphicon-ok'></span></font>"); return true; } }; //判断密码是否符合规范 function checkPsw1(){ var patrn = /^[a-zA-Z0-9]+$/; console.log((/\d/.test($(this).val()) && /[a-zA-Z]/.test($(this).val()) && patrn.test($(this).val()))); if (!(/\d/.test($(this).val()) && /[a-zA-Z]/.test($(this).val()) && patrn.test($(this).val()))) { $("#tishi1").html("<font color='red'>密码只能是6-20位并同时包含字母和数字</font>"); return false; } else { $("#tishi1").html("<font color='green'><span class='glyphicon glyphicon-ok'></span></font>"); return true; } }; //判断两次密码是否相同 function checkPsw2(){ var pwd1 = $("#pwd1").val(); var pwd2 = $(this).val(); if (pwd1 == pwd2) { $("#tishi2").html("<font color='green'><span class='glyphicon glyphicon-ok'></span></font>"); return true; console.log(1); //document.getElementById("submit").disabled = false; } else { $("#tishi2").html("<font color='red'>两次密码不相同</font>"); return false; console.log(2); //document.getElementById("submit").disabled = true; } }; //不带方法名的写法 $(function() { $("#yanzhengma").change(function() { var yanzhengma = $(this).val(); if(yanzhengma == ""){ $("#yanzhengTishi").html("<font color='red'>请输入验证码</font>"); return false; }else{ $("#yanzhengTishi").html("<font color='green'><span class='glyphicon glyphicon-ok'></span></font>"); return true; } }); $("#pwd1").change(function() { var patrn = /^[a-zA-Z0-9]+$/; console.log((/\d/.test($(this).val()) && /[a-zA-Z]/.test($(this).val()) && patrn.test($(this).val()))); if (!(/\d/.test($(this).val()) && /[a-zA-Z]/.test($(this).val()) && patrn.test($(this).val()))) { $("#tishi1").html("<font color='red'>密码只能是6-20位并同时包含字母和数字</font>"); return false; } else { $("#tishi1").html("<font color='green'><span class='glyphicon glyphicon-ok'></span></font>"); return true; } }); $("#pwd2").change(function() { var pwd1 = $("#pwd1").val(); var pwd2 = $(this).val(); if (pwd1 == pwd2) { $("#tishi2").html("<font color='green'><span class='glyphicon glyphicon-ok'></span></font>"); return true; console.log(1); //document.getElementById("submit").disabled = false; } else { $("#tishi2").html("<font color='red'>两次密码不相同</font>"); return false; console.log(2); //document.getElementById("submit").disabled = true; } }); //判断邮箱格式是否符合规范 /* $("#emailAd").change(function() { var emailAd = $(this).val(); var re=/^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/; if(re.test(emailAd)){ $("#emailTishi").html("<font color='green'><span class='glyphicon glyphicon-ok'></span></font>"); } else{ $("#emailTishi").html("<font color='red'>请输入正确的电子邮箱地址</font>"); } }); */ }); //点击提交时再次验证 function isSubmit() { alert(checkemail()); alert(checkCode()); alert(checkPsw1()); alert(checkPsw2()); alert(checkemail() && checkCode() && checkPsw1() && checkPsw2()); return checkemail() && checkCode() && checkPsw1() && checkPsw2(); }