其他分享
首页 > 其他分享> > 价格输入框的校验(数字,两个小数)

价格输入框的校验(数字,两个小数)

作者:互联网

 

1         <td ><input type="text" name="price" value="${storeProdute.retail_price }" id="price" size="5" style="text-align: right;"  
2              οnkeyup="checkNum(this)"></td>
3              <!-- οnkeyup="if(isNaN(value))execCommand('undo')" onafterpaste="if(isNaN(value))execCommand('undo')" -->

 

    function checkNum(obj){

        obj.value = obj.value.replace(/[^\d.]/g,"");
        
        obj.value = obj.value.replace(/^\./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');
        
    }

 

标签:function,obj,校验,value,replace,checkNum,输入框,小数
来源: https://www.cnblogs.com/xieling2100-fei/p/13824668.html