手机号码格式验证

/**
 * 验证手机号是否合法
 * @return
 */
public boolean isMobileNO(String mobile){
    if(mobile.length() != 11)
    {
        return false;
    }else{
        /**
         * 移动号段正则表达式
         */
        String pat1 = "^((13[4-9])|(147)|(15[0-2,7-9])|(17[2,8])|(18[2-4,7-8])|(198))\\d{8}|(1705)\\d{7}$";

        /**
         * 联通号段正则表达式
         * */
        String pat2  = "^((13[0-2])|(145)|(15[5-6])|(166)|(17[1,5,6])|(18[5,6]))\\d{8}|(1709)\\d{7}$";

        /**
         * 电信号段正则表达式
         */
        String pat3  = "^((133)|(149)|(153)|(17[3,7])|(18[0,1,9])|(199))\\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
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值