javascript数字全角转半角

先放上。

<!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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值