判断日期格式是否正确

/**
 * 判断日期格式是否正确
 * 
 * @param strDate
 * @return
 */
public boolean isValidDate(String strDate) {
SimpleDateFormat  dateFormat = new SimpleDateFormat("yyyyMMdd");
if (strDate == null) return false;
strDate.replaceAll("/", "");
strDate.replaceAll("-", "");        
try {
dateFormat.parse(strDate);
return true;
} catch (Exception e) {
// 格式不对
return false;
}
}

你可能感兴趣的:(JavaScript)