|
js判断时间
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; } 上面的是校验输入框内是否是日期,且格式是由数字和"-"符号构成;符合"yyyy-m-d"或"yyyy-m-dd"或"yyyy-mm-d"或"yyyy-mm-dd"的格式(即textObj.value.length为8、9、10中的一种) function isFloat(textObj){ var tmpFloatValue = textObj.value; var tmpLength = tmpFloatValue.length; var count = 0; for (var i = 0; i < tmpLength; i++){ aChar = tmpFloatValue.substring(i,i+1); if (aChar != "." && !isNumber(aChar)){ alert("请输入合法数字!"); textObj.focus(this); textObj.select(this); return false; } } for (var i = 0; i < tmpLength; i++){ aChar = tmpFloatValue.substring(i,i+1); count = 0; if (aChar == "."){ count++; } } if (count > 1){ alert("请输入正确的浮点数!"); textObj.focus(this); textObj.select(this); return false; } return true; } 上面的是校验输入框中输入的是否是数字 |
|
Time.2009-8-21 来源.http://www.gcity.com.cn 编辑.上海红提城信息科技有限公司
|
© 2002-2008 www.Gcity.com.cn 沪ICP备06055129号咨询热线:4008207959 021-33606181(红提城信息科技)
|