首页 > 移动平台 > 详细

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

时间:2021-09-06 05:19:18      阅读:34      评论:0      收藏:0      [点我收藏+]

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

\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;
    }
}

 

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

原文:https://www.cnblogs.com/taoshihan/p/15226871.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!