所以,我在我的邮件脚本中使用了eregi,但是最近,我得到了该函数被弃用的错误.
那么,替换以下代码的最简单方法是什么:
if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email'])))?
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏:)
if (!preg_match("/^[A-Z0-9.%-]+@[A-Z0-9.%-]+.[A-Z]{2,4}$/", trim($_POST['email'])))
Run Code Online (Sandbox Code Playgroud)
使用preg_match.
因为在PHP> = 5.3中不推荐使用ereg_*函数
另外,对于电子邮件验证,最好使用filter_var
if (!filter_var(trim($_POST['email']), FILTER_VALIDATE_EMAIL))
echo 'Email is incorrect';
Run Code Online (Sandbox Code Playgroud)