先放上。
检查输入的时间是否是正确的时间,输入格式为(YYYYMMDD)
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title> new document </title>
<meta name="generator" content="editplus">
<meta name="author" content="">
<meta name="keywords" content="">
<meta name="description" content="">
</head>
<body>
<script>
function convertNum(fullNum){
var fullNums = "0123456789";
var halfNums = "0123456789";
var index;
alert("fullNum is " + fullNum);
if ((index = halfNums.indexOf(fullNum))>0){
alert("I am a half num! and I will return directly");
return fullNum;
}
if ((index = fullNums.indexOf(fullNum))>0){
alert("I am a full numm! and I will return after convert");
return halfNums.charAt(index);
}
return NaN;
}
function checkNum(str,len){
alert("In checkNum ,str is " + str);
var result = "";
for(var i=0;i<str.length;i++){
alert("str[" + i + "] is " + str.charAt(i));
result +=convertNum(str.charAt(i));
}
alert("result is " + result + "result length is " + result.length);
var pattern = "/\\d{" + len + "}/";
alert("pattern is " + pattern);
if (null == result.match(eval(pattern))){
return false;
}
return true;
}
function doCheck(){
var num = document.getElementById("nn").value;
alert("In doCheck,num is " + num);
if(!checkNum(num,8)){
alert("Not a num!!!!");
} else {
alert("Is a num!!!!");
}
}
</script>
<input type="text" value="" id="nn" maxLength="8">
<input type="button" value="doCheck" onclick="doCheck();">
</body>
</html>
检查输入的时间是否是正确的时间,输入格式为(YYYYMMDD)
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title> new document </title>
<meta name="generator" content="editplus">
<meta name="author" content="">
<meta name="keywords" content="">
<meta name="description" content="">
</head>
<body>
<input type="text" value="" id="dd">
<input type="button" onclick="checkDate();">
<script>
function checkDate(){
var inputDate = document.getElementById("dd").value;
var y = parseInt(inputDate.substring(0,4),10);
var m = parseInt(inputDate.substring(4,6),10) - 1;
var d = parseInt(inputDate.substring(6,8),10);
var dt = new Date(y,m,d);
if(dt.getFullYear() != y || dt.getMonth() != m || dt.getDate() != d){
alert("wrong");
return false;
}
alert("current");
return true;
}
</script>
</body>
</html>