<?php
//过滤字符串的特殊字符
function checkform() {
var username = document.theform.user_name.value;
var realname = document.theform.real_name.value;
var passwd = document.theform.passwd.value;
var passwd2 = document.theform.passwd2.value;
var email = document.theform.email.value;
var question = document.theform.question.value;
var answer = document.theform.answer.value;
var address = document.theform.address.value;
var phone = document.theform.phone.value;
var answer = document.theform.answer.value;
var checkdata = /<|>|'|;|&|#|"|'/;
var checkusername = /[^0-9]/;
var checkmail = /^([a-za-z0-9_-])+@([a-za-z0-9_-])+(.[a-za-z0-9_-])+/;
var checkphone = /[^0-9-]/;
if ( username == "" ) {
alert("用户名不能为空!");
return false;
}
if ( passwd == "" ) {
alert("密码不能为空!");
return false;
}
if ( realname == "" ) {
alert("真实姓名不能为空!");
return false;
}
if ( question == "" ) {
alert("密码问题不能为空!");
return false;
}
if ( answer == "" ) {
alert("密码问题答案不能为空!");
return false;
}
if ( email == "" ) {
alert("e-mail不能为空!");
return false;
}
if ( checkusername.test(username) ) {
}else{
alert("用户名不能全为数字!");
return false;
}
if ( checkdata.test(username) ) {
alert("用户名包含非法字符,请不要使用特殊字符!");
return false;
}
if ( username.length > 28 || username.length < 3 ) {
alert("用户名长度不符合要求【3-28个字符】 username.length");
return false;
}
if ( passwd != passwd2 ) {
alert("两次输入的密码不一致!");
return false;
}
if ( passwd.length > 28 || passwd.length < 5 ) {
alert("密码长度不符合要求【5-28个字符】");
return false;
}
if ( checkdata.test(realname) ) {
alert("真实姓名包含非法字符,请不要使用特殊字符!");
return false;
}
if ( realname.length > 28 || realname.length < 3 ) {
alert("真实姓名长度不符合要求【3-28个字符】");
return false;
}
if ( question.length > 98 || question.length < 3 ) {
alert("密码提示问题长度不符合要求【6-98个字符】");
return false;
}
if ( answer.length > 98 || answer.length < 3 ) {
alert("问题答案长度不符合要求【3-98个字符】");
return false;
} //
脚本学堂 http://www.jb200.com
if ( ! checkmail.test(email) ) {
alert("e-mail包含非法字符!");
return false;
}
if ( email.length > 48 || email.length < 5 ) {
alert("e-mail长度不符合要求【5-48个字符】");
return false;
}
if ( checkdata.test(address) ) {
alert("联系地址包含非法字符!");
return false;
}
if ( address != "" && address.length > 48 ) {
alert("联系地址长度不符合要求【48个字符以内】");
return false;
}
if ( checkphone.test(phone) ) {
alert("联系电话包含非法字符!");
return false;
}
if ( address != "" && ( phone.length > 18 || phone.length < 7 ) ) {
alert("联系电话长度不符合要求【7-18个字符】");
return false;
}
}