Java最新的手机号验证代码

来源:互联网 发布:好看的倒计时软件 编辑:程序博客网 时间:2024/04/28 18:01

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
虚拟运营商:170、1718、1719
**

验证代码如下

**

    /**     * @see 验证手机号是否合法     * @param mobiles     * @return     */    public static boolean isMobileNO(String mobile){          if (mobile.length() != 11)        {            return false;        }else{            /**             * 移动号段正则表达式             */            String pat1 = "^((13[4-9])|(147)|(15[0-2,7-9])|(178)|(18[2-4,7-8]))\\d{8}|(1705)\\d{7}$";            /**             * 联通号段正则表达式             */            String pat2  = "^((13[0-2])|(145)|(15[5-6])|(176)|(18[5,6]))\\d{8}|(1709)\\d{7}$";            /**             * 电信号段正则表达式             */            String pat3  = "^((133)|(153)|(177)|(18[0,1,9])|(149))\\d{8}$";            /**             * 虚拟运营商正则表达式             */            String pat4 = "^((170))\\d{8}|(1718)|(1719)\\d{7}$";            Pattern pattern1 = Pattern.compile(pat1);            Matcher match1 = pattern1.matcher(mobile);            boolean isMatch1 = match1.matches();            if(isMatch1){                return true;            }            Pattern pattern2 = Pattern.compile(pat2);            Matcher match2 = pattern2.matcher(mobile);            boolean isMatch2 = match2.matches();            if(isMatch2){                return true;            }            Pattern pattern3 = Pattern.compile(pat3);            Matcher match3 = pattern3.matcher(mobile);            boolean isMatch3 = match3.matches();            if(isMatch3){                return true;            }            Pattern pattern4 = Pattern.compile(pat4);            Matcher match4 = pattern4.matcher(mobile);            boolean isMatch4 = match4.matches();            if(isMatch4){                return true;            }            return false;         }    } 

楼主自己验证过的,需要的朋友可以看看!

0 0