js 判斷input的值是否為數字


 
        
<input onkeyup="this.value=this.value.replace(/[^0-9-]+.[^0-9-]+/,'');" id="retailPrice" type="text" class="layui-input"
name="commodityDetails.retailPrice" required
oninput="OnInputMath (event)" onpropertychange="OnPropChangedMath (event)" placeholder="請輸入零售價" autocomplete="off"
class="layui-input">



function OnInputMath (event) {
layer.closeAll();
var reg=/^[1-9]\d*\.\d*|0\.\d*[1-9]\d*$/;
//正整數 reg = /^[1-9]+[0-9]*]*$/
if(event.target.value==""||reg.test(event.target.value)==true){

} else {
layer.msg("請輸入數字 ");
}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM