Email validation using regular expression in PHP

后端 未结 11 1546
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-30 01:38

I am pretty much new with regular expression. I am developing a project in PHP and i need to validate email address. After searching in this site and google i found the fol

11条回答
  •  半阙折子戏
    2020-11-30 02:29

    Use these regular expressions to perform a more thorough validation. For example it prevents adjacent periods in email address like aaa..bbb@example..com which is invalid according to RFC 822.

    function isValidEmail($email)
    {
        return preg_match('/\A[a-z0-9]+([-._][a-z0-9]+)*@([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,4}\z/', $email)
            && preg_match('/^(?=.{1,64}@.{4,64}$)(?=.{6,100}$).*/', $email);
    }
    

    See validate email address using regular expression in PHP.

提交回复
热议问题