javascript中对特殊字符的过滤
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;
}
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;
}
}