input框限制输入内容

			<input v-model="request.idCardNo" maxlength="18" @input="typeInput($event)" placeholder="请输入您的身份证号">

对应在methods中的方法

			typeInput(event) {
				// 只能输入数字和字母的验证;
				const inputType = /[\W]/g //想限制什么类型在这里换换正则就可以了
				this.$nextTick(function() {
					//这里的 this.request.idCardNo 是input框 v-model 绑定的值
					this.request.idCardNo = event.target.value.replace(inputType, '');
				})
			},

正则

只能输入数字
const inputType = /[^\d]/g		
只能输入字母
const inputType = /[^a-zA-Z]/g		
只能输入数字和字母
const inputType =/[\W]/g
只能输入小写字母
const inputType =/[^a-z]/g
只能输入大写字母
const inputType =/[^A-Z]/g
只能输入数字和字母和下划线
const inputType =/[^\w_]/g //下划线也可以改成%
只能输入中文
const inputType =/[^\u4E00-\u9FA5]/g
只能输入数字和小数点
const inputType =/[^\d.]/g
posted @   你笑的好瓜  阅读(59)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示