axdebnm
|
分享:
▲
一般都用JAVA SCRIPT 例如空格..亂填的..等的 可以用JAVA SCRIPT 來警告會員
進階一點的可以用PHP來做..不過跟JAVA也沒多大差別..
這邊提供一個...你回去慢慢搞...
<script language="javascript"> <!-- var form = ""; var submitted = false; var error = false; var error_message = "";
function check_input(field_name, field_size, message) { if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) { var field_value = form.elements[field_name].value;
if (field_value == '' || field_value.length < field_size) { error_message = error_message + "* " + message + "\n"; error = true; } } }
function check_radio(field_name, message) { var isChecked = false;
if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) { var radio = form.elements[field_name];
for (var i=0; i<radio.length; i++) { if (radio.checked == true) { isChecked = true; break; } }
if (isChecked == false) { error_message = error_message + "* " + message + "\n"; error = true; } } }
function check_select(field_name, field_default, message) { if (form.elements[field_name] && (form.elements[field_name].type != "hidden")) { var field_value = form.elements[field_name].value;
if (field_value == field_default) { error_message = error_message + "* " + message + "\n"; error = true; } } }
function check_password(field_name_1, field_name_2, field_size, message_1, message_2) { if (form.elements[field_name_1] && (form.elements[field_name_1].type != "hidden")) { var password = form.elements[field_name_1].value; var confirmation = form.elements[field_name_2].value;
if (password == '' || password.length < field_size) { error_message = error_message + "* " + message_1 + "\n"; error = true; } else if (password != confirmation) { error_message = error_message + "* " + message_2 + "\n"; error = true; } } }
function check_password_new(field_name_1, field_name_2, field_name_3, field_size, message_1, message_2, message_3) { if (form.elements[field_name_1] && (form.elements[field_name_1].type != "hidden")) { var password_current = form.elements[field_name_1].value; var password_new = form.elements[field_name_2].value; var password_confirmation = form.elements[field_name_3].value;
if (password_current == '' || password_current.length < field_size) { error_message = error_message + "* " + message_1 + "\n"; error = true; } else if (password_new == '' || password_new.length < field_size) { error_message = error_message + "* " + message_2 + "\n"; error = true; } else if (password_new != password_confirmation) { error_message = error_message + "* " + message_3 + "\n"; error = true; } } } function check_form(form_name) { if (submitted == true) { alert("這個表單已經送出,請按 Ok 後等待處理"); return false; }
error = false; form = form_name; error_message = "別急!別急!\n您的資料還沒填完喔!\n看看您漏掉哪些\n\n";
check_radio("gender", "請選擇性別."); check_input("firstname", 2, "中文姓名不得少於 2 個字"); check_input("lastname", 2, "暱稱不得少於 2 個字"); check_input("email_address", 6, "電子郵件不得少於 6 個字"); check_input("street_address", 2, "街道門牌號碼不得少於 2 個字"); check_input("postcode", 3, "郵遞區號不得少於 3 個字"); check_input("city", 1, "鄉/村鎮區不得少於 1 個字"); check_input("state", 2, "縣市最少必須 2個字"); check_select("country", "", "請從下拉式選單中選取國別"); check_input("telephone", 3, "電話號碼不得少於 3 個字"); check_password("password", "confirmation", 3, "密碼不得少於3 個字", "密碼不符"); check_password_new("password_current", "password_new", "password_confirmation", 3, "密碼不得少於3 個字", "新密碼不得少於3 個字", "密碼不符"); if (error == true) { alert(error_message); return false; } else { submitted = true; return true; } } //--></script>
|