1.只能输入正整数,且第一个不能为0,不能输入小数点
style="background-color:#efeff4;border:1px solid #4cd964;border-radius:5px;width:60px;height:25px; font-size:16px;text-align: center; padding: 0 3px!important;" placeholder="">
2.限制两位小数
给class为two-decimal的input框添加限制事件
$(".two-decimal").on("input",function(e){
e.target.value = e.target.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
e.target.value = e.target.value.replace(/^\./g,""); //验证第一个字符是数字而不是.
e.target.value = e.target.value.replace(/\.{2,}/g,"."); //只保留第一个. 清除多余的.
e.target.value = e.target.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");//只允许输入一个小数点
e.target.value = e.target.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
});
3.三位小数
7)value=value.slice(0,7)" pattern="[0-9]*\.?[0-9]{0,3}" >