//判斷郵箱是否符合規範 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(); }