PHP 匹配最新手机号运营商

 
 
   /**
     * @param $phone
     * @return int
     * 手机运营商检测
     */
    private function phone_check($phone)
    {

        $isPhone = "/^1[3-9]\d{9}$/"; //先判断正确手机号格式

        if (preg_match($isPhone, $phone)) {

            $isChinaMobile = "/^134[0-9]\d{7}$|^1703\d{7}$|^170[5-6]\d{7}$|^(?:13[5-9]|147|148|15[0-27-9]|178|18[2-478]|198)\d{8}$/"; //
            $isChinaUnion  = "/^1704\d{7}$|^170[7-9]\d{7}$|^171[0-9]\d{7}$|^(?:13[0-2]|145|15[56]|166|175|176|18[56])\d{8}$/"; //
            $isChinaTelcom = "/^(?:133|153|169|177|173|174|170|18[019]|199)\d{8}$|^170[0-2]\d{7}$/"; //

            if (preg_match($isChinaMobile, $phone)) {

                return 1; //中国移动
            } else if (preg_match($isChinaUnion, $phone)) {

                return 2; //中国联通
            } else if (preg_match($isChinaTelcom, $phone)) {

                return 3; //中国电信
            } else {
                return 0;
            }

        } else {
            return 0;

        }
    }

匹配规则依据:


如有更新号段请自行添加规则,留言提示帮助更新谢谢!

猜你喜欢

转载自blog.csdn.net/qq_24909089/article/details/80478695