1. 程式人生 > >PHP驗證郵箱合法性

PHP驗證郵箱合法性

/**
 * 驗證輸入的郵件地址是否合法
 *
 * @param   string      $email      需要驗證的郵件地址
 *
 * @return bool
 */
function is_email($user_email)
{
    $chars = "/^([a-z0-9+_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,6}\$/i";
    if (strpos($user_email, '@') !== false && strpos($user_email, '.') !== false)
    {
        if (preg_match($chars, $user_email)){
            return true;
        }
        else{
            return false;
        }
   }
   else{
            return false;
        }
}