- <el-input
- v-model="inputTable.amount"
- @input="formatNum(form.amount, 'amount')"
- ></el-input>
- formatNum(val, key) {
- 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"); //只能输入两个小数
- this.form[key] = temp;
- },