实现效果:
1. HTML代码
<el-form-item label="对公账号:" prop="num"><el-input v-model="ruleForm.num" maxlength="23 @keyup.native="validateNum(ruleForm.num)" placeholder="请输入对公账号"></el-input>
</el-form-item>
2. js代码
// 输入银行卡号validateNum(data) {this.setNum(data)},// 设置银行卡号,每四位添加一个空格setNum(data) {var res = ''res = data.replace(/\s/g, '').replace(/[^\d]/g, '').replace(/(\d{4})(?=\d)/g,'$1 ')this.$set(this.ruleForm, 'num', res)},