vue element adminvue+elementui常⽤到的输⼊框验证
1.验证输⼊框只能输⼊正整数
  <el-input :disabled="mainId?true:false" @keyup.native="maxNumGetInput(index2)" v-model="item.maximumReceiveAllowed" ></el-input>    maxNumGetInput(index) {
this.formData[index].maximumReceiveAllowed = this.formData[index].place(/[^\.\d]/g,'');
this.formData[index].maximumReceiveAllowed = this.formData[index].place('.','');
},
2.⾦额输⼊框且最多两位⼩数验证
  <el-input v-model="" @input="inputChange(index2)" @change="getPrice()"></el-input>
//监听输⼊框变化
inputChange(index) {
let self = this;
self.formData[index].money = self.inputnum(self.formData[index].money)
},
// 输⼊框最多两位⼩数
inputnum(val) {
let num = place(/[^\d.]/g, ""); //清除"数字"和"."以外的字符
num = place(/^\./g, ""); //验证第⼀个字符是数字
if (num.indexOf('.') == -1) { //⼩数点前留9位
if (num.length > 9) {
num = num.slice(0, 9);
}
} else {
if (num.split('.')[0].length > 9) {
num = num.split('.')[0].slice(0, 9) + '.' + num.split('.')[1];
}
}
num = place(/\.{2,}/g, ""); //只保留第⼀个, 清除多余的
num = place(".", "$#$").replace(/\./g, "").replace("$#$", ".");
num = place(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输⼊两个⼩数
return num
},

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。