Let the text box only enter numbers and points

Let the text box only enter numbers and points

    function clearNoNum(obj){    
      obj.value = obj.value.replace(/[^\d.]/g,"");  //清除“数字”和“.”以外的字符     
      obj.value = obj.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的     
      obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");    
      obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3');//只能输入两个小数     
      if(obj.value.indexOf(".")< 0 && obj.value !=""){//以上已经过滤,此处控制的是如果没有小数点,首位不能为类似于 01、02的金额    
       obj.value= parseFloat(obj.value);    
      }    
      //这是文本框  --上面是函数.经本人测试有效果
       <input type="text" name="je" onkeyup="clearNoNum(this)" />  
    }    

Guess you like

Origin blog.csdn.net/qq_37120477/article/details/90912083