Home >php教程 >PHP源码 >php中邮箱email 电话等格式的验证

php中邮箱email 电话等格式的验证

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-08 17:23:481920browse

本文章来给大家介绍我常用的一些邮箱email tel等格式的正则表达式,各位有需要了解学习的朋友不防进入参考。

<script>ec(2);</script>

1.email验证函数

 代码如下 复制代码

function isValidEmail($email) { 

    $email = strtolower($email);
    if (!preg_match(“/[^@]{1,64}@[^@]{1,255}/”, $email)) { 
        return false; 
    } 
    $email_array = explode(“@”, $email); 
    $local_array = explode(“.”, $email_array[0]); 
    $length = sizeof($local_array); 
    for ($i = 0; $i         if (!preg_match(“@^[a-z0-9_~-][a-z0-9_~.-]{0,63}$@”, $local_array[$i])) { 
            return false; 
        } 
    } 
    unset($length); 
    if (!preg_match(“@^[?[0-9.]+]?$@”, $email_array[1])) { 

        $domain_array = explode(“.”, $email_array[1]); 

        $length = sizeof($domain_array); 
        if ($length             return false; 
        } 
        for ($i = 0; $i             if (!preg_match(“/^(([a-z0-9][a-z0-9-]{0,61}[a-z0-9])|([a-z0-9]+))$/”, $domain_array[$i])) { 
                return false; 
            } 
        } 
    unset($length); 
    } 
    return true; 
}


2.验证移动电话是否符合规范

 代码如下 复制代码

function isValidCellPhone($cellPhone) { 

    $flag = FALSE; 

    if (preg_match(‘@^1[3458][0-9]{9}$@’, $cellPhone)) { 

        $flag = TRUE; 

    } 

    return $flag; 

3.验证电话是否符合规范 

 代码如下 复制代码

function isValidPhone($phone) { 

    if (preg_match(‘@^1[3458][0-9]{9}$@’, $phone)) { 

        return true; 

    } 

    if (preg_match(‘@((?:(?:(?:00860?|0)(?:10|2d|[3-9]dd))-?)?([2-8]d{6,7}))@’, $phone)){ 

        return true; 

    } 

    if (preg_match(‘@^([48]00(?:d{7}|-d{7}|-d{3}-d{4}|-d{4}-d{3}|d-d{3}-d{3}))$@’, $phone)) { 

        return true; 

    } 

    return false; 

}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn