|
|
| js判断时间 |
|
[ 作者:佚名 来源:网络 点击数:48 加入时间:2007-2-8 ] |
| 【双击左键自动滚屏】【图片上滚动鼠标滚轮变焦图片】
【字体:放大 正常 缩小】
字体颜色:
|
| 便民查询 中华五千年 世界五千年 万年历 天气预报 周公解梦 脑筋急转弯 在线翻译 电信话费查询 |
function verifyDate(textObj){
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;
}
上面的是校验输入框中输入的是否是数字
|
|
| 国家纸币 自考信息 度量转换 搜索引擎指南 城市经纬度 脑筋急转弯 各国资料 名言辞典 违章查询 |
·上一篇文章:window.open的例子和使用方法以及参数说明 ·下一篇文章:用Autoruns揪出流氓软件的驱动保护 |
| |
| 百度搜索更多内容:js判断时间 |
【推荐文档】 【打印文档】 【返回页首】 【关闭窗口】
|
|