(vue)手机号,验证码,身份证,姓名输入正则校验
<input class="phoneNumTF" @input="phoneNmVerification" :value="phoneNm" type="text" placeholder="请输入手机号" maxlength="11">
<input class="codeNumTF" @input="msgCodeNmVerification" :value="msgCode" type="text" placeholder="请输入验证码" maxlength="6">
<input class="infoContent" type="text" @input="idNumberVerification" :value="idNumber" placeholder="请输入您的有效身份证号码" maxlength="18">
<input class="infoContent" type="text" @input="nameVerification" :value="name" placeholder="请输入您的真实姓名" maxlength="15">
methods:{
//手机号输入校验(只允许输入数字)
phoneNmVerification(e){
e.target.value=e.target.value.replace(/([^0-9])+/g, '');
this.phoneNm = e.target.value;
},
//验证码输入校验(只允许输入数字)
msgCodeNmVerification(e){
e.target.value=e.target.value.replace(/([^0-9])+/g, '');
this.msgCode = e.target.value;
},
//身份证输入校验(只允许输入数字和Xx)
idNumberVerification(e){
e.target.value=e.target.value.replace(/([^0-9Xx])+/g, '');
this.idNumber = e.target.value;
},
//姓名校验(只允许输入汉字和英文)
nameVerification(e){
e.target.value=e.target.value.replace(/[^\u4e00-\u9fa5A-Za-z]/, '');
this.name = e.target.value;
},
}