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>
|