uniapp限制输入框只能输入数字、小数点、整数、字母正则
【代码】uniapp限制输入框只能输入数字、小数点、整数、字母正则。
文章共191字 · 阅读需要大约1分钟
一键AI生成摘要,助你高效阅读
问答
·
只能输入数字
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
使用方法
<u--input :placeholder="exchangeValue" border="surround" v-model="listData.integral"
@change="change($event,1)" type='number '></u--input>
change(e, num) {
const inputTypeNum = /[^\d]/g //数字
switch (num) {
case 1:
//要写nextTick 不然无效
this.$nextTick(() => {
this.listData.integral = e.replace(inputTypeNum, '');
})
break;
}
}
更多推荐
已为社区贡献1条内容
所有评论(0)