介绍:
此功能核心是正则和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, '')
		})
	}
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐