判断文本框为时间格式HH:mm
2012-08-30 18:43
267 查看
function isTime(s){
var str=$("#"+s).val();
if(str!=null&&str!=""){
var f=document.getElementById(s);
if(str.length == 5){
var j=str.indexOf(":");
var hour=str.substring(0,j);
var minute=str.substring(j+1);
if(j==-1){
alert("时间格式hh:mm");
f.focus();//获得焦点
return false;
}
if (hour>=24||minute>=60){
alert("输入范围时间格式有误!");
f.focus();
return false;
}
if (hour==23&&minute!=00){
return true;
}
}else {
alert("时间格式hh:mm");
f.focus();
return false;
}
var a = str.match(/^(\d{1,2})(:)?(\d{1,2})$/);
if (a == null){
alert("时间格式hh:mm");
f.focus();
return false;
}
if (a[1]>24||a[3]>60){
alert("时间格式hh:mm");
f.focus();
return false;
}
}
return true;
}
<tr>
<td align="right" width="55px" class="label-cell">
<span style="color: red;">*</span>时段名称
</td>
<td>
<s:textfield name="period.name" id="periodname"></s:textfield>
</td>
<td align="right" width="60px" class="label-cell">
开始签到时间
</td>
<td>
<s:textfield id="periodcheckInTime1" name="period.checkInTime1" onblur="isTime('periodcheckInTime1')"></s:textfield>
<s:hidden name="period.periodId" />
</td>
</tr>
<tr>
<td align="right" width="55px" class="label-cell">
<span style="color: red;">*</span>上班时间
</td>
<td>
<s:textfield name="period.startTime" id="periodStartTime" onblur="isTime('periodStartTime')"></s:textfield>
</td>
<td align="right" width="60px" class="label-cell">
结束签到时间
</td>
<td>
<s:textfield id="periodcheckInTime2" name="period.checkInTime2" onblur="isTime('periodcheckInTime2')"></s:textfield>
</td>
</tr>
<tr>
<td align="right" width="55px" class="label-cell">
<span style="color: red;">*</span>下班时间
</td>
<td>
<s:textfield name="period.endTime" id="periodEndTime" onblur="isTime('periodEndTime')"></s:textfield>
</td>
<td align="right" width="60px" class="label-cell">
开始签退时间
</td>
<td>
<s:textfield id="periodcheckOutTime1" name="period.checkOutTime1" onblur="isTime('periodcheckOutTime1')"></s:textfield>
</td>
</tr>
<tr>
<td align="right" width="60px" class="label-cell">
记迟到时间(分钟)
</td>
<td>
<s:textfield name="period.lateMinutes"></s:textfield>
</td>
<td align="right" width="60px" class="label-cell">
结束签退时间
</td>
<td>
<s:textfield id="periodcheckOutTime2" name="period.checkOutTime2" onblur="isTime('periodcheckOutTime2')"></s:textfield>
</td>
</tr>
<tr>
<td align="right" width="60px" class="label-cell">
记早退时间(分钟)
</td>
<td>
<s:textfield name="period.earlyMinutes"></s:textfield>
</td>
</tr>
var str=$("#"+s).val();
if(str!=null&&str!=""){
var f=document.getElementById(s);
if(str.length == 5){
var j=str.indexOf(":");
var hour=str.substring(0,j);
var minute=str.substring(j+1);
if(j==-1){
alert("时间格式hh:mm");
f.focus();//获得焦点
return false;
}
if (hour>=24||minute>=60){
alert("输入范围时间格式有误!");
f.focus();
return false;
}
if (hour==23&&minute!=00){
return true;
}
}else {
alert("时间格式hh:mm");
f.focus();
return false;
}
var a = str.match(/^(\d{1,2})(:)?(\d{1,2})$/);
if (a == null){
alert("时间格式hh:mm");
f.focus();
return false;
}
if (a[1]>24||a[3]>60){
alert("时间格式hh:mm");
f.focus();
return false;
}
}
return true;
}
<tr>
<td align="right" width="55px" class="label-cell">
<span style="color: red;">*</span>时段名称
</td>
<td>
<s:textfield name="period.name" id="periodname"></s:textfield>
</td>
<td align="right" width="60px" class="label-cell">
开始签到时间
</td>
<td>
<s:textfield id="periodcheckInTime1" name="period.checkInTime1" onblur="isTime('periodcheckInTime1')"></s:textfield>
<s:hidden name="period.periodId" />
</td>
</tr>
<tr>
<td align="right" width="55px" class="label-cell">
<span style="color: red;">*</span>上班时间
</td>
<td>
<s:textfield name="period.startTime" id="periodStartTime" onblur="isTime('periodStartTime')"></s:textfield>
</td>
<td align="right" width="60px" class="label-cell">
结束签到时间
</td>
<td>
<s:textfield id="periodcheckInTime2" name="period.checkInTime2" onblur="isTime('periodcheckInTime2')"></s:textfield>
</td>
</tr>
<tr>
<td align="right" width="55px" class="label-cell">
<span style="color: red;">*</span>下班时间
</td>
<td>
<s:textfield name="period.endTime" id="periodEndTime" onblur="isTime('periodEndTime')"></s:textfield>
</td>
<td align="right" width="60px" class="label-cell">
开始签退时间
</td>
<td>
<s:textfield id="periodcheckOutTime1" name="period.checkOutTime1" onblur="isTime('periodcheckOutTime1')"></s:textfield>
</td>
</tr>
<tr>
<td align="right" width="60px" class="label-cell">
记迟到时间(分钟)
</td>
<td>
<s:textfield name="period.lateMinutes"></s:textfield>
</td>
<td align="right" width="60px" class="label-cell">
结束签退时间
</td>
<td>
<s:textfield id="periodcheckOutTime2" name="period.checkOutTime2" onblur="isTime('periodcheckOutTime2')"></s:textfield>
</td>
</tr>
<tr>
<td align="right" width="60px" class="label-cell">
记早退时间(分钟)
</td>
<td>
<s:textfield name="period.earlyMinutes"></s:textfield>
</td>
</tr>
相关文章推荐
- C++判断时间格式满足yyyy-mm-dd-hh:mm与时间1小于时间2
- java判断字符串是否为HH:mm(时分格式)
- java中将毫秒转化为hh:mm:ss的时间格式
- Excel将秒转换成标准的时间格式HH:MM:SS
- [sql技巧]int型的(毫)秒数据如何转换成字符型的hh:mm:ss时间格式
- java判断时间格式 //格式必须为“YYYY-MM-dd”
- 判断时间大小 yyyy-MM-dd 格式
- 两种时间格式正则表达式HH:mm 和HH:mm:ss
- 时间戳格式化转换为日期格式,date.Format('yyyy/MM/dd hh:mm:ss')
- 将yyyyMMdd HH:mm:ss格式的时间转换成时间类型
- java校验时间格式 HH:MM
- 取当前时间 格式 yyyy年mm月dd日 hh:mm:ss weekday
- [乐意黎原创] 时间格式 yyyy-MM-dd'T'HH:mm:ss.SSSZ 中的T和Z表示什么
- 比较时间的大小("HH:MM")格式
- 判断是否为YYYY/MM/DD格式的时间
- 秒转 时间格式 JavaScript seconds to time with format hh:mm:ss
- Excel将秒转换成标准的时间格式HH:MM:SS
- vb中如何把hh:mm:ss的时间格式转换成多少分钟?
- JAVA判断时间格式为 "YYYY-MM-DD"
- java校验时间格式 HH:MM