在编写用户注册的程序时,常常需要验证用户所输入的信息是不是正确的,这时就需要对用户输入的信息进行验证。用户验证程序其实也有很多,往往要根据注册信息的不同需要而定。下面,以一个较普遍的的程序段加以说明:
if ($admin=="" or (strlen($admin)>16) or (strlen($admin)<2)) {
echo "<SCRIPT language=JavaScript>alert('请输入用户名(不能大于16小于2)');";
echo"this.location.href='vbscript:history.back()';</SCRIPT>";
}
if ($password=="" or strlen($password)>16 or strlen($password)<6) {
echo "<SCRIPT language=JavaScript>alert('密码长度为6-16个字符');";
echo"this.location.href='vbscript:history.back()';</SCRIPT>";
}
if ($password=="") {
echo "<SCRIPT language=JavaScript>alert('确认密码不能为空');";
echo"this.location.href='vbscript:history.back()';</SCRIPT>";
}else{
if ($password!=$password1) {
echo "<SCRIPT language=JavaScript>alert('密码和确认密码不一致');";
echo"this.location.href='vbscript:history.back()';</SCRIPT>";
}
}
if ($wt="") {
echo "<SCRIPT language=JavaScript>alert('密码问题不能为空');";
echo"this.location.href='vbscript:history.back()';</SCRIPT>";
}
if ($da="") {
echo "<SCRIPT language=JavaScript>alert('问题答案不能为空');";
echo"this.location.href='vbscript:history.back()';</SCRIPT>";
}
if ($qq!="") {
if (!is_numeric($qq)) {
echo "<SCRIPT language=JavaScript>alert('QQ号码必须是数字');";
echo"this.location.href='vbscript:history.back()';</SCRIPT>";
}
}
if ($youbian=="" or strlen($youbian)!=6) {
echo "<SCRIPT language=JavaScript>alert('请正确输入邮编');";
echo"this.location.href='vbscript:history.back()';</SCRIPT>";
}
if ($youbian!="") {
if (!is_numeric($youbian)) {
echo "<SCRIPT language=JavaScript>alert('邮编必须是数字');";
echo"this.location.href='vbscript:history.back()';</SCRIPT>";
}
}
if ($dizhi="") {
echo "<SCRIPT language=JavaScript>alert('住址不能为空');";
echo"this.location.href='vbscript:history.back()';</SCRIPT>";
}
if ($mail=="") {
echo "<SCRIPT language=JavaScript>alert('E-mail不能为空!');";
echo "this.location.href='vbscript:history.back()';</SCRIPT>";
}
if ($textarea=="") {
echo "<SCRIPT language=JavaScript>alert('个人说明不能为空!');";
echo "this.location.href='vbscript:history.back()';</SCRIPT>";
}
if ($textarea=="" or strlen(textarea)>150) {
echo "<SCRIPT language=JavaScript>alert('个人说明为150个字符');";
echo"this.location.href='vbscript:history.back()';</SCRIPT>";
}