您的位置:首页 > 其它

判断文本框为时间格式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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: