正则表达式 常用验证(Java)

  /**
     * 验证日期格式
     * @return true 格式正确,false 格式错误
     */
    public static boolean checkDateformat(String dateStr){
        String eL = "[0-9]{4}[-/]{1}[0-9]{2}[-/]{1}[0-9]{2}";
        Pattern p = Pattern.compile(eL);
        Matcher m = p.matcher(dateStr);
        boolean flag = m.matches();
        if (!flag) {
            System.out.println("格式错误");
        }else{
            System.out.println("格式正确");
        }
        return flag;
    }
原文地址:https://www.cnblogs.com/yuanye007/p/5731812.html