/**
* 严格的日期格式校验
* 1、日期格式严格为dd/MM/yyyy
* 2、日期要有效,如32/01/2017就是错误的
* @param str
* @return
*/
public boolean isValidDate(String str) {
DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
formatter.setLenient(false);
try {
Date date = (Date) formatter.parse(str);
return str.equals(formatter.format(date));
} catch (Exception e) {
return false;
}
}
正则验证
String eL = "[0-9]{2}/[0-9]{2}/[0-9]{4}";
Pattern p = Pattern.compile(eL);
Matcher m = p.matcher(str);
boolean dateFlag = m.matches();
if (!dateFlag) {
return false;
}