输入纯数字
<input type="text" id="costs" name="costs" onkeyup="checkNum(this)" lay-verify="required" class="layui-input" value="${object.costs}" >
window.checkNum = function (date) {
var num=date.value;
if(num!=0){
var reg = /^(?!(0[0-9]{0,}$))[0-9]{1,}[.]{0,}[0-9]{0,}$/;
if (reg.test(num)) {
$("#totalAmount").val(total);
}else{
date.value="";
layer.msg("请输入数字!", {icon: 0});
}
}
}
正整数正则校验
<input type="text" id="costs" name="costs" onkeyup="checkNum(this)" lay-verify="required" class="layui-input" value="${object.costs}" >
window.checkNum = function (date) {
var num=date.value;
//var reg = /^(?!(0[0-9]{0,}$))[0-9]{1,}[.]{0,}[0-9]{0,}$/; //>0不包括0的整数正则
var reg = /^[1-9]\d*$/;
if (reg.test(num)) {
$("#totalAmount").val(total);
}else{
date.value="";
layer.msg("请输入数字!", {icon: 0});
}
}