- <!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" οnclick="doCheck();">
- </body>
- </html>
数字的全角转半角
最新推荐文章于 2024-07-03 03:20:18 发布