通过正则表达式  限制输入框 只能录入数字和小数点,且小数点后只能录入两位小数,

input 上绑定input事件,

<el-input @input="numberFn('itemBudget')" v-model="formLabelAlign.itemBudget"></el-input>
<el-input  @input="numberFn('itemTotalInvestment')" v-model="formLabelAlign.itemTotalInvestment"></el-input>
<el-input  @input="numberFn('itemGroupInvestment')" v-model="formLabelAlign.itemGroupInvestment"></el-input>

 

numberFn(p){
    this.formLabelAlign[p] = this.formLabelAlign[p]
    .replace(/[^\d^\.]+/g, '')  
    .replace(/^0+(\d)/, '$1')
    .replace(/^\./, '0.')
    .match(/^\d*(\.?\d{0,2})/g)[0] || ''
},

 

Logo

前往低代码交流专区

更多推荐