只能输入数字
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;
}
}