JAVA 正则表达式 手机验证

 public static void main(String [] args){
        String phone = "16666666666";
        String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";
        if (phone.length() != 11) {
            System.out.println("手机号应为11位数");

        } else {
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(phone);
            boolean macth = m.matches();
            if (!macth) {
                System.out.println("请填入正确的手机号");
            }else {
                System.out.println("正确");
            }
        }
    }
发布了72 篇原创文章 · 获赞 16 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/qq_40206199/article/details/89355624
今日推荐