<script language="javascript">
// 注意:调用checkDate()函数即可,以下是调用函数的例子,把“ /* */ ”去掉就可以测试
function checkDate(ys)
{
if(ys.split(":")[0]/1>23||ys.split(":")[0]/1<0||isNaN(ys.split(":")[0]))
{alert( ys+"/r error hour");
return false;
}
if(ys.split(":")[1]/1>59||ys.split(":")[1]/1<0||isNaN(ys.split(":")[1]))
{alert( ys+"/r error minute");
return false;
}
alert( ys+"/r right")
}
/*
checkDate("ccccc") //false
checkDate("12/30"); //false
checkDate("12-30"); //false
checkDate("12:30"); //false 中文冒号
checkDate("0q:16") //false
checkDate("25:16") //false
checkDate("05:ad") //false
checkDate("05:60") //false
checkDate("12321"); //false
checkDate("12/30"); //false
checkDate("29:12"); //false
checkDate("10:60"); //false
checkDate("25:72"); //false
checkDate("10:72"); //false
checkDate("5:8"); //true
checkDate("15:8"); //true
checkDate("5:32"); //true
checkDate("05:12"); //true
checkDate("12:30"); //true
*/
</script>
已用过的:
<script language="javascript" type="text/javascript" >
//判断日期函数
function isdate(str){
var strSeparator = "-"; //日期分隔符
var strDateArray;
var intYear;
var intMonth;
var intDay;
var boolLeapYear;
var strDate;
strDate=str;
strDateArray = strDate.split(strSeparator); //以“-”为分隔符提取年月日
if(strDateArray.length!=3) {
//alert("您输入的日期错误");
return "false";
}
intYear = parseInt(strDateArray[0],10);
intMonth = parseInt(strDateArray[1],10);
intDay = parseInt(strDateArray[2],10);
if(isNaN(intYear)||isNaN(intMonth)||isNaN(intDay)) {
//alert("您输入的日期错误");
return "false";}
if(intMonth>12||intMonth<1){
// alert("日期错误,月份必须为0到12之间的一个数");
return "false";}
if((intMonth==1||intMonth==3||intMonth==5||intMonth==7||intMonth==8||intMonth==10||intMonth==12)&&(intDay>31||intDay<1)){
// alert("日期错误,您输入月份的相应日份必须为1—31之间");
return "false";
}
if((intMonth==4||intMonth==6||intMonth==9||intMonth==11)&&(intDay>30||intDay<1)) {
// alert("日期错误,您输入月份的相应日份必须为1—30之间");
return "false";}
if(intMonth==2){
if(intDay<1) {
// alert("日期错误,月份不能为零或空值");
return "false";}
boolLeapYear = false;
if((intYear%400==0)||(intYear%4==0 && intYear%100!=0)) //判断闰年
boolLeapYear = true;
else
boolLeapYear = false; //平年
if(boolLeapYear){
if(intDay>29) {
// alert("日期错误,闰年2月份的日份必须在1—29之间");
return "false";}
}
else{
if(intDay>28) {
//alert("日期错误,2月份的日份必须在1—28之间");
return "false";}
}
}
return "true";
}
// 判断时间函数
function checkDate(ys)
{
if(ys.split(":")[0]/1>23||ys.split(":")[0]/1<0||isNaN(ys.split(":")[0]))
{alert("对不起,您输入的结束时间无效");
return "false";
}
if(ys.split(":")[1]/1>59||ys.split(":")[1]/1<0||isNaN(ys.split(":")[1]))
{alert("对不起,您输入的结束时间无效");
return "false";
}
return "true";
}
//判断输入特殊字符
function FISSTR(sV,sR){
var sTmp;
if(sV.length==0)
{ return (false);}
for (var i=0; i < sV.length; i++)
{
sTmp= sV.substring (i, i+1);
if (sR.indexOf (sTmp, 0)>-1)
{return (false);}
}
return (true);}
//check 主函数
function check(){
if(document.form1.begindate.value!=""){
if(isdate(document.form1.begindate.value)=="false"){
alert("起始日期输入格式不正确/r请输入正确的日期");
document.form1.begindate.focus();
return false;
}
}
if(document.form1.enddate.value!=""){
if(isdate(document.form1.enddate.value)=="false"){
alert("结束日期输入格式不正确/r请输入正确的日期");
document.form1.enddate.focus();
return false;
}
}
//日期比较
var rukua,rukub,rukuc,sca,scb,scc,fir,sec;
fir=document.form1.begindate.value.split("-");
sec=document.form1.enddate.value.split("-");
rukua=parseInt(sec[0]);
rukub=parseInt(sec[1]);
rukuc=parseInt(sec[2]);
sca=parseInt(fir[0]);
scb=parseInt(fir[1]);
scc=parseInt(fir[2]);
if(sca>rukua){
alert("结束日期不能小于起始日期");
document.form1.enddate.focus();
return false;
}
if(sca==rukua && scb>rukub){
alert("结束日期不能小于起始日期");
document.form1.enddate.focus();
return false;
}
if(sca==rukua && scb==rukub && scc>rukuc){
alert("结束日期不能小于起始日期");
document.form1.enddate.focus();
return false;
}
// 判断时间输入是否有误
if (document.form1.endtime.value!=""){
if(checkDate(document.form1.endtime.value)=="false"){
document.form1.endtime.focus();
return false;
}
if ( !FISSTR(document.form1.endtime.value," :|*& ^%$#@!")){
alert("结束时间输入有误/r输入不能含有空格或则中文冒号等特殊字符");
document.form1.endtime.focus();
return false;
}
// 时间比较
if(sca==rukua &&scb==rukub && scc==rukuc ){
btime=document.form1.begintime.value;
etime=document.form1.endtime.value;
// 把结束时间变成规范时间
etim=etime.split(":")
etim1=parseInt(etim[0]);
etim2=parseInt(etim[1]);
if (etim1>=1 && etim1<=9) //小时
etim1="0"+etim1;
if(etim2>=1 && etim2<=9) //分钟
etim2="0"+etim2;
etime=etim1+":"+etim2;
btime=btime.toString(btime).replace(":","0");
etime=etime.toString(etime).replace(":","0");
if( btime>etime){
alert("结束时间输入有误/r结束时间不能小于起始时间");
document.form1.endtime.focus();
return false;
}
}
}
}
<form action="rc_xg.asp" method="post" name="form1" onSubmit="return check()">
起始日期:
<select name="begin_nian">
<%for i=2000 to 2020%>
<%if i=year(date()) then %>
<option value="<%=year(date())%>" selected="selected"><%=year(date())%></option>
<%else%>
<option value="<%=i%>"><%=i%></option>
<%end if%>
<%next%>
</select>年
<select name="begin_yue">
<%for i=1 to 12%>
<%if i=month(date()) then %>
<option value="<%=month(date())%>" selected="selected"><%=month(date())%></option>
<%else%>
<option value="<%=i%>"><%=i%></option>
<%end if%>
<%next%>
</select>月
<select name="begin_ri">
<%for i=1 to 31%>
<%if i=day(date()) then %>
<option value="<%=day(date())%>" selected="selected"><%=day(date())%></option>
<%else%>
<option value="<%=i%>"><%=i%></option>
<%end if%>
<%next%>
</select>日
起始时间:
<input name="begintime" type="text" size="10" maxlength="15" value="<%=FormatdateTime(now(),4)%>" disabled="disabled"/>
结束日期:
<select name="end_nian">
<%for i=2000 to 2020%>
<%if i=year(date()) then %>
<option value="<%=year(date())%>" selected="selected"><%=year(date())%></option>
<%else%>
<option value="<%=i%>"><%=i%></option>
<%end if%>
<%next%>
</select>年
<select name="end_yue">
<%for i=1 to 12%>
<%if i=month(date()) then %>
<option value="<%=month(date())%>" selected="selected"><%=month(date())%></option>
<%else%>
<option value="<%=i%>"><%=i%></option>
<%end if%>
<%next%>
</select>月
<select name="end_ri">
<%for i=1 to 31%>
<%if i=day(date()) then %>
<option value="<%=day(date())%>" selected="selected"><%=day(date())%></option>
<%else%>
<option value="<%=i%>"><%=i%></option>
<%end if%>
<%next%>
</select>日
结束时间:
<input name="endtime" type="text" size="10" maxlength="5" />
</form>