html代码
<input class="form-control" v-model="userName" type="text" placeholder="用户名" @blur="blur" @input="userNameLimit">
<input class="form-control" v-model="userPassword" type="password" placeholder="密码" @input="userPasswordLimit">
**js部分**
//只能输入英文、数字
userPasswordLimit:function() {
this.userPassword = this.userPassword.replace(/[^\a-\z\A-\Z0-9]/g, '')
},
// 限制输入特殊字符
userNameLimit:function() {
this.userName = this.userName.replace(/[ `~!@#$%^&*()_\-+=<>?:"{}|,.\/;'\\[\]·~!@#¥%……&*()——\-+={}|《》?:“”【】、;‘’,。、]/g, '')
},
本文介绍如何使用Vue.js限制HTML输入框中特殊字符的输入,包括用户名仅限英文和数字,密码排除特定符号,通过正则表达式实现。
3421

被折叠的 条评论
为什么被折叠?



