function doCustomValidation() { var email = $("#email").val(); var email_confirm = $("#email_confirm").val(); if (email != email_confirm) { alert("郵箱地址不一致"); return false; } $.post("./saveInfo.jsp", $("#myform").serialize(), function(data, textStatus) { if ("success" == jQuery.trim(textStatus)) { data = $.trim(data); if ("" != data) { var msg = data.split(","); alert(msg[0]); if (msg.length > 1) { if (msg[1] == "true") { window.location.reload(); } else { $("#" + msg[1]).focus(); } } } else { alert("伺服器出錯,請稍後再試"); } } else { alert("伺服器出錯,請稍後再試"); } }); return false; } $(function() { // init button group $("#ser_type .btn").click(function() { $("#ser_type .btn").removeClass("active"); $(this).addClass("active"); $("[name=ser_type]").val($(this).html()); }); $("#call .btn").click(function() { $("#call .btn").removeClass("active"); $(this).addClass("active"); $("[name=call]").val($(this).html()); }); $("#callBackDate .btn").click(function() { $("#callBackDate .btn").removeClass("active"); $(this).addClass("active"); $("[name=callBackDate]").val($(this).val()); }); $("#callBackTime .btn").click(function() { $("#callBackTime .btn").removeClass("active"); $(this).addClass("active"); $("[name=callBackTime]").val($(this).html()); }); // form valid var frmvalidator = new Validator("myform"); frmvalidator.addValidation("ser_type", "req", "請選擇服務計劃"); /* * frmvalidator.addValidation("acct_no", "req", "請填上帳戶號碼"); * frmvalidator.addValidation("acct_no", "regexp=\\d{8}-\\d{3}", * "請填寫正確帳戶號碼"); */ frmvalidator.addValidation("call", "req", "請選擇稱謂"); frmvalidator.addValidation("name", "req", "請填上名稱"); frmvalidator.addValidation("email", "req", "請填上電郵地址"); frmvalidator.addValidation("email", "maxlen=50", "請填寫正確電郵地址"); frmvalidator.addValidation("email", "email", "請填寫正確電郵地址"); frmvalidator.addValidation("email_confirm", "req", "請填上確認電郵地址"); frmvalidator.addValidation("email_confirm", "maxlen=50", "請填寫正確確認電郵地址"); frmvalidator.addValidation("email_confirm", "email_confirm", "請填寫正確確認電郵地址"); frmvalidator.addValidation("mobile", "req", "請填上聯絡手提電話"); frmvalidator.addValidation("mobile", "minlen=8", "請填寫正確聯絡手提電話"); frmvalidator.addValidation("mobile", "maxlen=8", "請填寫正確聯絡手提電話"); frmvalidator.addValidation("mobile", "numeric", "請填寫正確聯絡手提電話"); frmvalidator.addValidation("mobile", "first_char", "請填寫正確聯絡手提電話"); frmvalidator.addValidation("callBackDate", "req", "請選擇聯絡日期"); frmvalidator.addValidation("callBackTime", "req", "請選擇回覆時間"); frmvalidator.addValidation("tAndC", "boxcheck", "請接受有關私隱政策及個人資料收集聲明內之條款"); frmvalidator.setAddnlValidationFunction(doCustomValidation); });