java使用正则表达式判断手机号是否正确,验证是否为座机号码+手机号码(CharUtil中国)+ 400 + 800电话 + 手机号号码(中国香港)

使用java,验证是否为座机号码+手机号码(CharUtil中国)+ 400 + 800电话 + 手机号号码(中国香港),正则表达式
1.正则表达式

   /**
     * 移动电话
     * eg: 中国大陆: +86  180 4953 1399,2位区域码标示+11位数字
     * 中国大陆 +86 Mainland China
     */
    public static final String MOBILE = "(?:0|86|\\+86)?1[3-9]\\d{9}";
    /**
     * 中国香港移动电话
     * eg: 中国香港: +852 5100 4810, 三位区域码+10位数字, 中国香港手机号码8位数
     */
    public static final String MOBILE_HK = "(?:0|852|\\+852)?\\d{8}";
    /**
     * 中国台湾移动电话
     * eg: 中国台湾: +886 09 60 000000, 三位区域码+号码以数字09开头 + 8位数字, 中国台湾手机号码10位数
     * 中国台湾 +886 Taiwan 国际域名缩写:TW
     */
    public static final String MOBILE_TW = "(?:0|886|\\+886)?(?:|-)09\\d{8}";
    /**
     * 中国澳门移动电话
     * eg: 中国澳门: +853 68 00000, 三位区域码 +号码以数字6开头 + 7位数字, 中国澳门手机号码8位数
     * 中国澳门 +853 Macao 国际域名缩写:MO
     */
    public static final String MOBILE_MO = "(?:0|853|\\+853)?(?:|-)6\\d{7}";
    /**
     * 座机号码<br>
     * pr#387@Gitee
     */
    public static final String TEL = "(010|02\\d|0[3-9]\\d{2})-?(\\d{6,8})";

2.直接复制完整代码运行


import java.util.regex.Pattern;

public class Test {

    /**
     * 移动电话
     * eg: 中国大陆: +86  180 4953 1399,2位区域码标示+11位数字
     * 中国大陆 +86 Mainland China
     */
    public static final String MOBILE = "(?:0|86|\\+86)?1[3-9]\\d{9}";
    /**
     * 中国香港移动电话
     * eg: 中国香港: +852 5100 4810, 三位区域码+10位数字, 中国香港手机号码8位数
     */
    public static final String MOBILE_HK = "(?:0|852|\\+852)?\\d{8}";
    /**
     * 中国台湾移动电话
     * eg: 中国台湾: +886 09 60 000000, 三位区域码+号码以数字09开头 + 8位数字, 中国台湾手机号码10位数
     * 中国台湾 +886 Taiwan 国际域名缩写:TW
     */
    public static final String MOBILE_TW = "(?:0|886|\\+886)?(?:|-)09\\d{8}";
    /**
     * 中国澳门移动电话
     * eg: 中国澳门: +853 68 00000, 三位区域码 +号码以数字6开头 + 7位数字, 中国澳门手机号码8位数
     * 中国澳门 +853 Macao 国际域名缩写:MO
     */
    public static final String MOBILE_MO = "(?:0|853|\\+853)?(?:|-)6\\d{7}";
    /**
     * 座机号码<br>
     * pr#387@Gitee
     */
    public static final String TEL = "(010|02\\d|0[3-9]\\d{2})-?(\\d{6,8})";

    /**
     * 座机号码+400+800电话
     *
     * @see <a href="https://baike.baidu.com/item/800">800</a>
     */
    public static final String TEL_400_800 = "0\\d{2,3}[\\- ]?[1-9]\\d{6,7}|[48]00[\\- ]?[1-9]\\d{2}[\\- ]?\\d{4}";

    public static void main(String[] args) throws Exception {
       //验证是否为座机号码+手机号码(CharUtil中国)+ 400 + 800电话 + 手机号号码(中国香港)
        String phone = "020-37690333";//广州天河政务服务中心电话号码

        Pattern mobile = Pattern.compile(MOBILE);
        Pattern mobileHk = Pattern.compile(MOBILE_HK);
        Pattern mobileTw = Pattern.compile(MOBILE_TW);
        Pattern mobileMo = Pattern.compile(MOBILE_MO);
        Pattern tel = Pattern.compile(TEL);
        Pattern tel_400_800 = Pattern.compile(TEL_400_800);

        if (mobile.matcher(phone).matches() || mobileHk.matcher(phone).matches() || mobileTw.matcher(phone).matches()
        || mobileMo.matcher(phone).matches() || tel.matcher(phone).matches()  || tel_400_800.matcher(phone).matches()){
            System.out.println("号码正确");
        } else {
            System.out.println("号码不正确");
        }
    }

}


在这里插入图片描述

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

飞机飞上天空

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值