uniapp input限制只能输入数字、汉字、字母等

2023-10-16  本文已影响0人  迷失的信徒
<input class="uni-input info-content input-len" type="text" maxlength="30" @input="replaceInput" v-model="value" />

replaceInput(event){
    const screeningStr = /[^\d]/g;      //想禁止什么类型,在这里替换正则就可以了
    if(screeningStr.test(event.target.value)){
          this.value = event.target.value.replace(screeningStr,'');
    }eles{
          this.value = event.target.value;
    }
}

相关正则表达式如下

只能输入数字
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
上一篇 下一篇

猜你喜欢

热点阅读