第一种方法
直接在oninput中写正则表达式
<el-input v-model="inputValue" placeholder="0.1" style="width:50px" oninput ="value=value.replace(/[^0-9.]/g,'')">
第二种方法
先写个methods方法
methods:
RexNum00_99(Num) {
let result = true
var numReg = /^[+-]?((\d*(\.\d{0,2})$)|(\d{1,2}$))/
var numRe = new RegExp(numReg)
if (!numRe.test(Num)) {
this.$message({
type: 'warning',
message: '请输入00.00-99.99的数值 ',
showClose: true,
})
result = false
}
return result
},
然后通过watch监视数据变化来验证
watch:
inputValue: function(newData, oldData) {
if (newData != "") {
if (!this.RexNum00_99(newData)) {
this.inputValue= oldData
}
}
},