<input type="text" onblur="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')" onkeyup="value=value.replace(/^\D*(\d*(?:\.\d{0,2})?).*$/g, '$1')" class="layui-input" value="" id="money" name="money">
var money=document.getElementById("money").value;
if(money==null||money==""||money==undefined){ layer.msg("金额不能为空"); return false; }
var regPos = /^\d+(\.\d+)?$/; //非负浮点数 // var regNeg = /^(-(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*)))$/; //负浮点数 if(regPos.test(money)){ }
来源:oschina
链接:https://my.oschina.net/u/4174369/blog/3211868