首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

证验时间格式是否正确输入

2012-12-21 
验证时间格式是否正确输入private boolean isDateStr(Date date){if(datenull) {return false}DateForm

验证时间格式是否正确输入
private boolean isDateStr(Date date){
if(date==null) {
return false;
}
DateFormat fmt = new SimpleDateFormat("yyyy-MM-dd");
try{
fmt.format(date);
return true;
}catch (Exception e) {
return false;
}
   
}


if(null!= domain.getCheckTime() && !isDateStr(domain.getCheckTime()))
{
result.addErrorMessage(bf.append(getColumNo("maternityCardCheckTime")).append("查验时间输入格式有问题").toString());
}


这样只允许输入诸如2012-2-3这样的数据,如果用户乱输入数据如2221111这样的数据就会报错。 1 楼 terra 2012-09-13   用正则表达式更简单吧

热点排行