美文网首页
uniapp input限制只能输入数字、汉字、字母等

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

作者: 迷失的信徒 | 来源:发表于2023-10-16 11:32 被阅读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

相关文章

网友评论

      本文标题:uniapp input限制只能输入数字、汉字、字母等

      本文链接:https://www.haomeiwen.com/subject/uvvxidtx.html