v-input 控制银行账号每4个数字用空格分割

<el-input v-model="PJJFform.cpBankZh" @input="cpBankZhFormat()"></el-input>

methods:{
	cpBankZhFormat:function () {
	    this.PJJFform.cpBankZh=this.PJJFform.cpBankZh.replace(/\s/g, '').replace(/[^\d]/g, '').replace(/(\d{4})(?=\d)/g, '$1 ')
    }
}

效果图:
在这里插入图片描述
如果在后续接口传参数时,需要把空格去掉,就把对应字段进行如下处理:

this.PJJFform.cpBankZh=this.PJJFform.cpBankZh.trim().replace(/\s/g,"")
发布了51 篇原创文章 · 获赞 8 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_44171757/article/details/102619265