zoukankan      html  css  js  c++  java
  • 正则表达式验证手机和邮箱格式

    if (!function_exists("check_mobile")) {
    /**
    * 检验手机号格式
    * @param $phone 手机号
    * @param int $countryCode 区号
    * @return bool
    * User: 陈启泽
    * DateTime: 2020/9/22 14:35
    */
    function check_mobile($phone,$countryCode=86)
    {
    $phone = trim($phone);
    if (empty($countryCode)) {
    $countryCode = 86;
    }
    if ($countryCode == 86 ) {
    $chars = "/^1[3-9]{1}[0-9]{1}[0-9]{8}$/";
    if (preg_match($chars, $phone)) {
    return true;
    }
    }else if ($countryCode == 852) {
    if (preg_match('/^[0-9]{8}$/', $phone)) {
    return true;
    }
    }else if ($countryCode == 60) {
    if (preg_match('/^0?1(1d{8}|[02-9]d{7})$/', $phone)) {
    return true;
    }
    }else {
    if (preg_match('/^[0-9]*$/', $phone)) {
    return true;
    }
    }


    return false;
    }
    }

    if (!function_exists("check_email")) {
    /**
    * 检验邮箱格式
    * @param string $email 邮箱
    * @return boolean bool true格式正确,false格式错误
    * User: 陈启泽
    * DateTime: 2020/9/22 14:44
    */
    function check_email($email){
    $email = trim($email);
    if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    return true;
    }else{
    return false;
    }
    }
    }
  • 相关阅读:
    go 正则表达式
    go 发送邮件
    beego 定时任务
    go 字符串操作
    BARTScore试试
    《A method for detecting text of arbitrary shapes in natural scenes that improves text spotting》笔记
    CPM-2
    Foxmail配置qq邮箱
    声音克隆MockingBird
    多模态摘要综述
  • 原文地址:https://www.cnblogs.com/qize/p/13897773.html
Copyright © 2011-2022 走看看