<input type="text" name="bankId" v-model="userBankId" @keyup="handleKeyup"" placeholder="请填写银行卡" maxlength="24" />
// 银行卡四位空格
handleKeyup() {
this.userBankId = this.userBankId.replace(/\D/g, ""); // 不允许输入非数字字符
this.userBankId = this.userBankId.replace(/(\d{4})(?=\d)/g, "$1 "); // 4位一组,非获取匹配最后一组数字,避免删除到空格时会马上自动补齐
},
网友评论