<el-input
v-model="money"
@input="formatNum($event, 'amount')"
></el-input>
//输入金额的限制
formatNum(val, key) {
console.log("e==",val)
let temp = val.toString();
temp = temp.replace(/。/g, ".");
temp = temp.replace(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
temp = temp.replace(/^\./g, ""); //验证第一个字符是数字
temp = temp.replace(/\.{2,}/g, ""); //只保留第一个, 清除多余的
temp = temp.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
temp = temp.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3"); //只能输入两个小数
temp = temp.replace(/^0+\./,'0.');
temp=temp.replace(/^0+([0-9])/,'$1');
this.money=temp
},
限制el-input只能输入正数 js
最新推荐文章于 2024-09-13 14:01:06 发布