不允许汉字
state.rulesForm.username = value.replace(/[\u4e00-\u9fa5]/gi, "");
只允许数字和字母
state.rulesForm.username = value.replace(/[^a-zA-Z0-9]+/g, "");
只允许数字
state.rulesForm.qlmId = value.replace(/[^0-9]/g, "");
只允许数字和字母和符号
this.form.username = this.form.username.replace(/[^a-zA-Z0-9@#$%^&*()._+=?\-,]+/g, "");
只允许字母和汉字
this.form.contact = this.form.contact.replace(/[^A-Za-z\u4e00-\u9fa5]+/g, "");
写法1
onInput(){
state.rulesForm.qlmId = value.replace(/[^0-9]/g, "");
}
写法1
<el-input v-model="form.mobilePhone" placeholder="请输入手机号" maxlength="11" οninput="value=value.replace(/[^\d\-\d]/g,'')">
</el-input>