if (isNaN(Date.parse("MM/DD/YYYY"))){}
if (isNaN(Date.UTC(year, month, day))) {}
if (isNaN(Date.UTC(year, month, day))) {}
解决方案 »
- JqueryEasyUI datagrid 右键菜单问题!
- 紧急!!!紧急!!各位大侠帮帮忙!!
- JS 集合类的对象定义问题
- js 中 符号的意思
- 动态的添加Ext TabPanel时,为什么它的html不能直接显示,要点击一下才显示
- 求一简单js代码(30分钟后结贴)
- 高分求助,在线等,急!
- 好几个链接都指向同一个页面,只是显示的内容不同,点击链接,就弹出页面窗口,怎么保证弹出的这个窗口一直保持在页面上.
- 关于后台处理form里面的action的问题!
- asp中默认的语言是vbscript,怎样改成javascript?这样在调用ASP的内建对象时有什么不同?
- 用Microsoft Visual InterDev 6.0编写关于xml的js的奇怪问题!
- 如何用程序生成一个本地机器上一个类的实例??
if ((Date.parse("MM/DD/YYYY")+"")=="NaN" ){}
或
if ((Date.UTC(year, month, day))+"")=="NaN") {}
var tmpDateValue = textObj.value;
var tmpLength = tmpDateValue.length;
if (tmpLength == 0){
return true;
}
for (var i = 0; i < tmpLength;i++){
aChar = tmpDateValue.substring(i,i+1);
if(aChar != "-" && (aChar < "0" || aChar > "9")) {
alert ("请按照格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
}
if ((tmpLength < 8 || tmpLength > 10) && tmpLength != 0) {
alert ("请按照格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
for (var j= 0; j < 4;j++){
aChar = tmpDateValue.substring(j,j+1);
if(aChar < "0" || aChar > "9") {
alert ("请按照格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
}
if (tmpDateValue.substring(4,5) != "-" || tmpDateValue.substring(5,6) == "-"){
alert ("请按规定格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
if (tmpLength == 8){
if (tmpDateValue.substring(6,7) != "-" || tmpDateValue.substring(7,8) == "-" ){
alert ("请按规定格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
}
if (tmpLength == 9){
if (tmpDateValue.substring(8,9) == "-" ){
alert ("请按规定格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
}
if (tmpLength == 10){
if (tmpDateValue.substring(7,8) != "-" || tmpDateValue.substring(6,7) == "-" || tmpDateValue.substring(8,9) == "-" || tmpDateValue.substring(9,10) == "-" ){
alert ("请按规定格式输入日期(yyyy-mm-dd)。");
textObj.focus(this);
textObj.select(this);
return false;
}
}
var count=0;
for (var k = 0; k < tmpLength;k++){
aChar = tmpDateValue.substring(k,k+1);
if(aChar == "-") {
count++;
}
}
if (count!=2){
alert("请按照格式输入日期!(yyyy-mm-dd)");
textObj.focus(this);
textObj.select(this);
return false;
}
return true;
}
把年月日给用户选择<select>那样出错的机会会小很多。。至少格式上不会出错。。