class EmailType
{
private $mailtype;
function mailtype($mail)
{
$this->mailtype=$mail;
//PHP5.3版本前使用以下IF
//if(!ereg(“^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+”,$this->mailtype))
if(!preg_match(“/^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/”,$this->mailtype))
//PHP5.3以后版本方法
{
echo “<script language=\”JavaScript\”>alert(\”邮箱格式不对\”);</script>”;
echo “<script>setTimeout(\”this.location=’index.php’\”,0);</script>”;exit;
}
}
}
ereg和preg_match函数的差别其实就是头尾多个/
关于作者