Java String match only digit

Description

Java String match only digit


public class Main {
    public static void main(String[] argv) throws Exception {
        String text = "";
        System.out.println(verifyIdCard(text));
    }/* w w w .  j  a va2s.  c o  m*/

    public static boolean verifyIdCard(String text) {
        boolean flag = false;
        String reg1 = "[0-9]{17}";
        String reg2 = "[0-9]{15}";
        String reg3 = "[0-9]{18}";
        flag = text.matches(reg1) || text.matches(reg2) || text.matches(reg3);
        return flag;
    }
}



PreviousNext

Related