Java最新的手机号验证代码

Java最新的手机号验证代码

**

运营商号段如下:

** 
中国联通号码:130、131、132、145(无线上网卡)、155、156、185(iPhone5上市后开放)、186、176(4G号段)、175(2015年9月10日正式启用,暂只对北京、上海和广东投放办理) 
中国移动号码:134、135、136、137、138、139、147(无线上网卡)、150、151、152、157、158、159、182、183、187、188、178 
中国电信号码:133、153、180、181、189、177、173、149、199 
虚拟运营商:170、1718、1719 
**

验证代码如下

 1   /**
 2      * @see 验证手机号是否合法
 3      * @param mobiles
 4      * @return
 5      */
 6     public static boolean isMobileNO(String mobile){  
 7         if (mobile.length() != 11)
 8         {
 9             return false;
10         }else{
11             /**
12              * 移动号段正则表达式
13              */
14             String pat1 = "^((13[4-9])|(147)|(15[0-2,7-9])|(178)|(18[2-4,7-8]))\\d{8}|(1705)\\d{7}$";
15             /**
16              * 联通号段正则表达式
17              */
18             String pat2  = "^((13[0-2])|(145)|(15[5-6])|(176)|(18[5,6]))\\d{8}|(1709)\\d{7}$";
19             /**
20              * 电信号段正则表达式
21              */
22             String pat3  = "^((133)|(153)|(177)|(18[0,1,9])|(149)|(199))\\d{8}$";
23             /**
24              * 虚拟运营商正则表达式
25              */
26             String pat4 = "^((170))\\d{8}|(1718)|(1719)\\d{7}$";
27 
28             Pattern pattern1 = Pattern.compile(pat1);
29             Matcher match1 = pattern1.matcher(mobile);
30             boolean isMatch1 = match1.matches();
31             if(isMatch1){
32                 return true;
33             }
34             Pattern pattern2 = Pattern.compile(pat2);
35             Matcher match2 = pattern2.matcher(mobile);
36             boolean isMatch2 = match2.matches();
37             if(isMatch2){
38                 return true;
39             }
40             Pattern pattern3 = Pattern.compile(pat3);
41             Matcher match3 = pattern3.matcher(mobile);
42             boolean isMatch3 = match3.matches();
43             if(isMatch3){
44                 return true;
45             }
46             Pattern pattern4 = Pattern.compile(pat4);
47             Matcher match4 = pattern4.matcher(mobile);
48             boolean isMatch4 = match4.matches();
49             if(isMatch4){
50                 return true;
51             }
52             return false; 
53         }
54     } 

文章转自:https://blog.csdn.net/chou342175867/article/details/62423314

转载于:https://www.cnblogs.com/walblog/articles/9287617.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值