【问题标题】:Checking if email is valid using Pregmatch error? [duplicate]使用 Pregmatch 错误检查电子邮件是否有效? [复制]
【发布时间】:2013-03-15 19:35:33
【问题描述】:

您好,我想检查电子邮件是否有效,例如 blabla@blabla.com,而不仅仅是纯文本“BLbalbalba”。

我有这个功能:

function VerifyEmail($address) 
{
   $Syntax='#^[w.-]+@[w.-]+.[a-zA-Z]{2,5}$#';
   if(preg_match($Syntaxe,$adrdess))
      return true;
   else
     return false;
}

然后像这样检查它:

    $email = htmlentities($_POST['email']);
if (!empty($email) && !empty($password) && !empty($message) && VerifyEmail($email) === true) {

得到这些错误:

Notice: Undefined variable: Syntaxe in C:\xampp\htdocs\recover\inc\functions.inc.php on line 20

Notice: Undefined variable: adrdess in C:\xampp\htdocs\recover\inc\functions.inc.php on line 20

Warning: preg_match() [function.preg-match]: Empty regular expression in C:\xampp\htdocs\recover\inc\functions.inc.php on line 20

Notice: Undefined variable: Syntaxe in C:\xampp\htdocs\recover\inc\functions.inc.php on line 20

Notice: Undefined variable: adrdess in C:\xampp\htdocs\recover\inc\functions.inc.php on line 20

Warning: preg_match() [function.preg-match]: Empty regular expression in C:\xampp\htdocs\recover\inc\functions.inc.php on line 20

为什么会这样?我做错了什么?这是检查电子邮件是否有效的稳定方法吗? 谢谢!

【问题讨论】:

  • $Syntax != $Syntaxe
  • 接受解决您问题的答案...:)

标签: php email


【解决方案1】:

不,它不是“稳定的”,它不是“有效的”,它不会做得很好。使用

filter_var($email, FILTER_VALIDATE_EMAIL)

相反。相关文档:http://www.php.net/manual/en/function.filter-var.php

【讨论】:

    【解决方案2】:

    这里有一些拼写错误

    应该是

    function VerifyEmail($address) 
    {
       $Syntax='#^[w.-]+@[w.-]+.[a-zA-Z]{2,5}$#';
       if(preg_match($Syntax,$address))
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-18
      • 2011-10-07
      • 1970-01-01
      • 2023-03-22
      • 1970-01-01
      • 2010-12-19
      • 2018-01-31
      • 1970-01-01
      相关资源
      最近更新 更多