介绍:
此功能核心是正则和replace替换函数,只能输入数字和字母,其他的替换成空值,相当于删除非匹配项
html:
<input @input="onKeyVinInput" type="text" maxlength='6' v-model="customerDetails.vin" placeholder="请输入车架号后6位" />
js:
// 车架号
onKeyVinInput(event) {
var value = event.detail.value.toUpperCase()
if (!value || value == " ") {
return ''
}
// 数字和字母
// const rule = /[\W]/g
// 数字和大写字母
const rule = /[^0-9A-Z]/g
this.$nextTick(() => {
this.customerDetails.vin = value.replace(rule, '')
})
}