求助,如何验证这样的输入日期 一定要這樣做才可以嗎?現在不少人都用select來限制client所輸入的資料矣既省時間而且不用太多check case新手拙見,請勿見笑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以用下拉的日历输入,源代码要的话跟我联系:[email protected]或者用下面的函数检验,日期格式改成你要的//////////////////////////////////////////////////////////检查输入的时间是否符合指定的格式,格式改为你要的/////////////////////////////////////////////////////////function checkT(strTC){ flg=0; temp=""; for (var i=0;i<strTC.length;i++) { cmp="0123456789-"; tst=strTC.substring(i,i+1); temp = temp + "*" + tst; if (cmp.indexOf(tst)<0) { flg++; } } if (flg!=0) { return(false); } return(true);}function valDate(M, D, Y){ Months= new Array(31,28,31,30,31,30,31,31,30,31,30,31); Leap = false; if((Y % 4 == 0) && ((Y % 100 != 0) || (Y %400 == 0))) Leap = true; if((D < 1) || (D > 31) || (M < 1) || (M > 12) || (Y < 0)) return(false); if((D > Months[M-1]) && !((M == 2) && (D > 28))) return(false); if(!(Leap) && (M == 2) && (D > 28)) return(false); if((Leap) && (M == 2) && (D > 29)) return(false); }function formatDate(dateField){ cDate = dateField.value; dSize = cDate.length; aCount = 0; bCount = 0; cCount = 0; if(cDate=='' || dSize==0) { alert("请输入日期!"); dateField.focus(); return(false); } if(!checkT(cDate)) { alert("输入的日期格式必须是:年-月-日\n例如:2003-1-1"); dateField.focus(); return(false); } for(var i=0; i < dSize; i++) { (cDate.substr(i,1) == "-") ? aCount++ : aCount; } if ((aCount != 2)) { alert("输入的日期格式必须是:年-月-日\n例如:2003-1-1"); dateField.focus(); return(false); } //将输入的日期字符串分隔成3部分 (Month, Day & Year idxBar1 = cDate.indexOf("-"); idxBar2= cDate.lastIndexOf("-"); strM = cDate.substring(idxBar1+1,idxBar2); strD = cDate.substring(idxBar2+1,dSize); strY = cDate.substring(0,idxBar1); //alert("strY = "+strY+"\nstrM = "+strM+"\nstrD = "+strD); //检测输入的年份是2位数还是4位数; ySize = strY.length if(ySize!=2 && ySize!=4 ) { alert('您输入的日期错误 !'); dateField.focus(); return false; } strM = (strM.length < 2 ? '0'+strM : strM); strD = (strD.length < 2 ? '0'+strD : strD); if(strY.length == 2) strY = (strY > 50 ? '19'+strY : '20'+strY); dateField.value = strY+'-'+strM+'-'+strD ok = valDate(strM, strD, strY); if(ok==false) { alert("您输入的日期错误 !"); dateField.focus(); return false; }} asp 中 不是可以用isdate()来校验的么? ky99xing(kk)大侠帮帮忙~! 我正在找一个简单实用的拖动式日历控件,可否发一个给我,[email protected]谢谢!! JS实现checkbox多选(使用鼠标直接进行括先) js 中2进制 位运算问题 新手学习,请老师们帮忙~感谢感谢! js文本框 发布:带滚动条可调整列宽的数据表格 请问怎么用ASP将文本转换为JS字符串? 一个iframe滚动条的问题。 这个正则表达试怎么写? 请问怎样控制一个“_blank”链接打开后的窗口属性(宽,高,是否显示工具条……) 请教各位:下拉框的问题. textarea中源文件的“汉字”是乱码!怎么办啊?搞了一上午了,大侠帮我!!! 关于boolean值的一点经验,不对的或者漏掉的请指正
////////////////////////////////////////////////////////
//检查输入的时间是否符合指定的格式,格式改为你要的//
///////////////////////////////////////////////////////
function checkT(strTC)
{
flg=0;
temp="";
for (var i=0;i<strTC.length;i++)
{
cmp="0123456789-";
tst=strTC.substring(i,i+1);
temp = temp + "*" + tst;
if (cmp.indexOf(tst)<0)
{
flg++;
}
}
if (flg!=0)
{
return(false);
}
return(true);
}function valDate(M, D, Y)
{
Months= new Array(31,28,31,30,31,30,31,31,30,31,30,31);
Leap = false;
if((Y % 4 == 0) && ((Y % 100 != 0) || (Y %400 == 0))) Leap = true;
if((D < 1) || (D > 31) || (M < 1) || (M > 12) || (Y < 0)) return(false);
if((D > Months[M-1]) && !((M == 2) && (D > 28))) return(false);
if(!(Leap) && (M == 2) && (D > 28)) return(false);
if((Leap) && (M == 2) && (D > 29)) return(false);
}function formatDate(dateField)
{
cDate = dateField.value;
dSize = cDate.length;
aCount = 0;
bCount = 0;
cCount = 0;
if(cDate=='' || dSize==0)
{
alert("请输入日期!");
dateField.focus();
return(false);
}
if(!checkT(cDate))
{
alert("输入的日期格式必须是:年-月-日\n例如:2003-1-1");
dateField.focus();
return(false);
}
for(var i=0; i < dSize; i++)
{
(cDate.substr(i,1) == "-") ? aCount++ : aCount;
}
if ((aCount != 2))
{
alert("输入的日期格式必须是:年-月-日\n例如:2003-1-1");
dateField.focus();
return(false);
}
//将输入的日期字符串分隔成3部分 (Month, Day & Year
idxBar1 = cDate.indexOf("-");
idxBar2= cDate.lastIndexOf("-");
strM = cDate.substring(idxBar1+1,idxBar2);
strD = cDate.substring(idxBar2+1,dSize);
strY = cDate.substring(0,idxBar1);
//alert("strY = "+strY+"\nstrM = "+strM+"\nstrD = "+strD);
//检测输入的年份是2位数还是4位数;
ySize = strY.length
if(ySize!=2 && ySize!=4 )
{
alert('您输入的日期错误 !');
dateField.focus();
return false;
}
strM = (strM.length < 2 ? '0'+strM : strM);
strD = (strD.length < 2 ? '0'+strD : strD);
if(strY.length == 2) strY = (strY > 50 ? '19'+strY : '20'+strY);
dateField.value = strY+'-'+strM+'-'+strD
ok = valDate(strM, strD, strY);
if(ok==false)
{
alert("您输入的日期错误 !");
dateField.focus();
return false;
}
}
我正在找一个简单实用的拖动式日历控件,可否发一个给我,
[email protected]
谢谢!!