正则表达式问题请高手解答
6位年月日验证yyMMdd平闰年要考虑还有14位日期验证yyyyMMddhhmmss(只要这种固定格式,不要带“/”、”-“之类的,只要固定的一种写法的
谢谢高手 --------------------编程问答--------------------
public class MatchDate {
public static boolean isLegalDate(String dateString) {
String regeb = "^(?:(?!0000)[0-9]{4}(?:(?:0[1-9]|1[0-2])(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)0229)((0[0-9])|(1[0-9])|(2[0-3]))[0-5][0-9][0-5][0-9]$";
return dateString.matches(regeb);
}
public static void main(String[] args) {
for (int i = 1990; i <= 2020; i++) {
String dateString = i + "0229235959";
System.out.println(dateString + " isLegalDate = "
+ isLegalDate(dateString));
}
}
}
/*
19900229235959 isLegalDate = false
19910229235959 isLegalDate = false
19920229235959 isLegalDate = true
19930229235959 isLegalDate = false
19940229235959 isLegalDate = false
19950229235959 isLegalDate = false
19960229235959 isLegalDate = true
19970229235959 isLegalDate = false
19980229235959 isLegalDate = false
19990229235959 isLegalDate = false
20000229235959 isLegalDate = true
20010229235959 isLegalDate = false
20020229235959 isLegalDate = false
20030229235959 isLegalDate = false
20040229235959 isLegalDate = true
20050229235959 isLegalDate = false
20060229235959 isLegalDate = false
20070229235959 isLegalDate = false
20080229235959 isLegalDate = true
20090229235959 isLegalDate = false
20100229235959 isLegalDate = false
20110229235959 isLegalDate = false
20120229235959 isLegalDate = true
20130229235959 isLegalDate = false
20140229235959 isLegalDate = false
20150229235959 isLegalDate = false
20160229235959 isLegalDate = true
20170229235959 isLegalDate = false
20180229235959 isLegalDate = false
20190229235959 isLegalDate = false
20200229235959 isLegalDate = true
*/
--------------------编程问答-------------------- 19960331111111 这个就处理不了
补充:Java , Java相关