龙空技术网

java使用正则表达式判断手机号是否正确,验证是否为座机号码

聪颖火车A7GKl 24

前言:

现在大家对“正则表达式判断手机号码”大概比较注重,兄弟们都想要剖析一些“正则表达式判断手机号码”的相关内容。那么小编同时在网上搜集了一些关于“正则表达式判断手机号码””的相关内容,希望兄弟们能喜欢,我们一起来学习一下吧!

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

1.java的手机号正则表达式

   /**     * 移动电话     * 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=";>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("号码不正确");        }    }}

标签: #正则表达式判断手机号码