JAVA regular expression phone verification

 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("正确");
            }
        }
    }
Published 72 original articles · won praise 16 · views 20000 +

Guess you like

Origin blog.csdn.net/qq_40206199/article/details/89355624