public static boolean verifyYYYYMM(String date){ String regex = "^(20|19){1}[0-9]{2}(((0){1}[1-9]{1})|((1){1}(0|1|2){1}))$"; boolean matches = Pattern.matches(regex, date); System.out.println(matches); return matches; }