如何在PHP中验证电子邮件? [英] How to validate an Email in PHP?

查看:317
本文介绍了如何在PHP中验证电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用php5验证输入值是有效的电子邮件地址.现在,我正在使用此代码

How can I validate the input value is a valid email address using php5. Now I am using this code

function isValidEmail($email){ 
     $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$"; 

     if (eregi($pattern, $email)){ 
        return true; 
     } 
     else { 
        return false; 
     }    
} 

,但显示不赞成使用的错误.我该如何解决此问题.请帮助我.

but it shows deprecated error. How can I fix this issue. Please help me.

推荐答案

您可以使用filter_var()函数,该函数为您提供了许多方便的验证和消毒选项.

You can use the filter_var() function, which gives you a lot of handy validation and sanitization options.

filter_var($email, FILTER_VALIDATE_EMAIL)

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆