[PHP] 验证手机号格式和邮箱格式的正则表达式

经常使用的正则,验证是否是手机号或者邮箱

w的意思是  [a-zA-Z0-9_] 这几个字符

+意思是1次到多次

*意思是0次到多次

? 意思是0次到1次

<?php
class Helper{
    /**
     * 验证手机号
     * @param $mobile
     * @return bool
     */
    public static function isMobile($mobile){
        if (empty($mobile)) {
            return false;
        }
        $eg = "/^(((d{2,3}))|(d{3}-))?1(3|4|5|6|7|8|9)d{9}$/";
        if (preg_match($eg, $mobile)) {
            return true;
        }
        return false;
    }

    /**
     * 验证邮箱
     * @param $email
     * @return bool
     */
    public static function isEmail($email){
        if (empty($email)) {
            return false;
        }
        $eg = "/^w+([-+.]w+)*@w+([-.]w+)*.w+([-.]w+)*$/";
        if (preg_match($eg, $email)) {
            return true;
        }
        return false;
    }
}

开源作品

GO-FLY,一套可私有化部署的免费开源客服系统,安装过程不超过五分钟(超过你打我 !),基于Golang开发,二进制文件可直接使用无需搭开发环境,下载zip解压即可,仅依赖MySQL数据库,是一个开箱即用的网页在线客服系统,致力于帮助广大开发者/中小站长快速整合私有客服功能
github地址:go-fly
官网地址:https://gofly.sopans.com
原文地址:https://www.cnblogs.com/taoshihan/p/15226871.html