Here you can find the source of isDate(String str)
public static boolean isDate(String str)
//package com.java2s; import java.util.Calendar; import com.google.common.base.Strings; public class Main { public static final String DATE = "(([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))-02-29)"; public static boolean isDate(String str) { if (!Strings.isNullOrEmpty(str) && str.matches(DATE)) { Calendar cal1 = Calendar.getInstance(); Calendar cal2 = Calendar.getInstance(); cal1.setTime(java.sql.Date.valueOf(str)); cal2.setTimeInMillis(new java.util.Date().getTime()); return Math.abs(cal1.get(Calendar.YEAR) - cal2.get(Calendar.YEAR)) <= 50; }/*from www. j ava 2 s . co m*/ return false; } }