考虑左位补0且规避掉空格的方法
this.form.inputNum = (rule,value,callback) => {// 保单号码校验 左位补零&&去除空格 var reg = /^[\d\s]+$/; if(!reg.test(value) && this.form.inputNum){ this.$message({ message : '请输入不超过15位数字', type : "error" }) this.form.inputNum = '' }else if(this.form.inputNum.length < 15 && this.form.inputNum.length){//输入数字不满15位,前面自动补0 var inputNum = this.form.inputNum.replace(/\s+/g,'') var length = 15 - inputNum.length; var str = ''; for(var i = 0; i < length; i++){ str = str + 0; } this.form.inputNum = str + inputNum; }else{ callback() } };