日期校验yyyyMMdd, 包括闰月等校验.
package com.xgcd; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * @Author: liangyadong * @Date: 2019/7/10 0010 15:25 * @Description: */ public class BatchTest { public static void main(String[] args) { //正则表达式校验日期格式 String date = "20050229"; String eL = "(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})(((0[13578]|1[02])(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)(0[1-9]|[12][0-9]|30))|(02(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))0229)"; Pattern pat = Pattern.compile(eL); Matcher matcher = pat.matcher(date); boolean boo = matcher.matches(); System.out.println(boo);// false } }