onkeyup="value=value.replace(/[^\d]/g,'') "onbeforepaste="clipboardData.setData('text',clipboardData.getData('text').replace(/[^\d]/g,''))"

解决方案 »

  1.   

    function checkIsFloat(){
         var nc=event.keyCode;
     var tf=document.getElementById('textfield');
         var s=tf.value;
     if((nc>=48) && (nc<=57) ){
       var ndot=s.indexOf('.');
       if(ndot!=-1){
         if((s.length-ndot>6) ||(ndot>10)){
       event.keyCode=0; return;
     }else if(ndot>10){
       tf.value='';
     }
       }else{
         if(s.length>10){
       tf.value='';
     }
       }
     }else if(nc==46){
       for(var i=0;i<s.length;i++){
         if(s.charAt(i)=='.'){
       event.keyCode=0; return;
     }
       }
     }else{
       event.keyCode=0;return;
     }
      }<input type="text" name="textfield" onKeyPress="checkIsFloat();">
      

  2.   

    to numen27(影子):
    好像不行,我的小数点也输不上了
      

  3.   

    改一下,这样就完美了
      function checkIsFloat(){
         var nc=event.keyCode;
     var tf=document.getElementById('textfield');
         var s=tf.value;
     if((nc>=48) && (nc<=57) ){
       var ndot=s.indexOf('.');
       if(ndot!=-1){
         if(s.length-ndot>6 ){
       event.keyCode=0; return;
     }
       }else{
         if(s.length>=10){
               event.keyCode=0;tf.value=''; return;
     }
       }
     }else if(nc==46){
       for(var i=0;i<s.length;i++){
         if(s.charAt(i)=='.'){
       event.keyCode=0; return;
     }
       }
     }else{
       event.keyCode=0;return;
     }
      }
    <input type="text" name="textfield" onKeyPress="checkIsFloat();">
      

  4.   

    function isSpecifyDecimal(str,intLen,speciLen)
         {
           if (str.length != 0)
           {
             // is number
             if (str.search(/[^0-9.]/g) != -1){
               return false;//不是数字
             }
               var dateArray=str.split(".");
               if ((dateArray.length > 2))
               {
                 return false;//有两个'.'
               }
               else if(dateArray.length == 1){//没有小数点
                 if(str.length > intLen)//intLen整数位数
                   return false;//超过整数位数
               }
               else{//有小数点
                 if (dateArray[0].length > intLen)
                 {
                   return false;
                 }
                 if (dateArray[1].length > speciLen)
                 {
                   return false;
                 }           }       }
           return true;    }
      

  5.   

    <script>
    function aa(){
    var a,b,c,d
    a=document.form1.text1.value
    b=a.length
    if(b<=17){
       for(c=0,c<=b,c++){
       d=c+1
          if(a.substr(c,d)%2==0){
             if(a.substr(c,d)%2==1){
                 if(String(d).lenght<=10){
                 document.alert("符合标准")
                                         }
                 else{
                 document.alert("不符合标准")
                     }  
                                         }       
            else{
                 if(a.substr(c,d)=="."){
                     if(a.substr(c,d)%2==0){
                         if(a.substr(c,d)%2==1){
                             if(String(d).lenght<=7){
                             document.alert("符合标准")
                                                    }
                                               }
                                            }
                                       }
                 }
          else{
          document.alert("不符合标准")
              }
                           }
              }
    </script>
      

  6.   

    或者
    <script>
      function bb(){
      var a,b,c,d
      a=document.form1.text1.vlaue
      c=String(a)
      b=a.length
      if(a%2==0){
         if(a%2==1){
                   }
                }
         else{
             if(a=="."){
             d++
                if(c.length<=10){
            
                                }
                else{
                document.alert("不符合标准")
                    }
                      }
             else{
             document.alert("不符合标准")
             }
             c=String(a)+String(a)
             if(c.length<=17){
             document.alert("不符合标准")
             else{
             c=document.form1.text1.vlaue
                 }
                 if(d>1){
                 document.alert("不符合标准")
                 } 
             }
    abc=setTimeout("bb()",10)
    }
    <body>
    <form name="from1">
    <input type="text" name="text1" onfocus="bb()">
    </form>
    </body>
      

  7.   

    上面的有错误  
    function bb(){
      var a,b,c,d
      d=0
      a=document.form1.text1.vlaue
      c=String(a)
      b=a.length
      if(a%2==0){
         if(a%2==1){
                   }
                }
         else{
             if(a=="."){
             d++
                if(c.length<=10){
            
                                }
                else{
                document.alert("不符合标准")
                    }
                      }
             else{
             document.alert("不符合标准")
             }
             c=String(a)+String(a)
             if(c.length<=17){
             document.alert("不符合标准")
             else{
             c=document.form1.text1.vlaue
                 }
                 if(d>1){
                 document.alert("不符合标准")
                 } 
             }
    abc=setTimeout("bb()",10)
    }
    <body>
    <form name="from1">
    <input type="text" name="text1" onfocus="bb()">
    </form>
    </body>
      

  8.   

    onKeyDown如果没理解我写完整代码好了