PHP常用手机、邮箱正则表达式代码片段

作者:IT技术圈子 阅读:521 日期:2025年05月22日

-- 广告 --

19元流量卡免费申请

免费领!官方认证!运营商正规流量卡(移动/联通/电信/广电),19元/月192G 免费申请包邮到家,限时领取!扫码办理哦:

yyy

  正文  

验证手机号码

/**
 * 验证手机号码格式
 * @param $mobile 手机号码
 */
function check_mobile($mobile){
    if(preg_match('/1[34578]\d{9}$/',$mobile))
        return true;
    return false;
}

验证邮箱

/**
 * 验证邮箱地址格式
 * @param $email 邮箱地址
 */
function check_email($email){
    if(filter_var($email,FILTER_VALIDATE_EMAIL))
        return true;
    return false;
}

验证固定电话

/**
 * 验证固定电话
 * @param $mobile
 * @return bool
 */
function check_telephone($mobile){
    if(preg_match('/^([0-9]{3,4}-)?[0-9]{7,8}$/',$mobile))
        return true;
    return false;
}


  END