<el-input
v-model="queryParams.totalBillYue"
:maxlength="20"
clearable
@input="getNumIpt"
@change="getChangeIpt"
placeholder="请输入入池资产总额"
></el-input>
1、对小数位数不限要求
getNumIpt(val) {
// 非数字 一位小数点 开头不能是小数
this.queryParams.totalBillYue = val
.replace(/[^\d.]/g, "")
.replace(/^(\d+)\.(\d*).*$/, "$1.$2")
.replace(/^\.*$/g, "");
},
getChangeIpt(val) {
// 处理小数点后无数字情况,例如12.处理为12
this.queryParams.totalBillYue = val.replace(/^(\d+)\.$/, "$1");
},
2、只能输入两位小数,需要变化一下第二个replace的正则,其他不变。
// 非数字 一位小数点 开头不能是小数
this.queryParams.totalBillYue = val
.replace(/[^\d.]/g, "")
.replace(/^(\d+)\.(\d\d).*$/, "$1.$2")
.replace(/^\.*$/g, "");