uniapp input框校验数据格式,只能输入汉字/数字/字母等

input框常用的正则表达式

<input class="uni-input iptStyle" name="input" placeholder="未识别出信息" v-model="form.fpNum" @input="fpNumInput" maxlength='24' />

fpNumInput(e) {
    
    
				const o = e.target;
				const inputRule = /^(0+)|[^\d]+/g  //修改inputRule 的值
				this.$nextTick(function() {
    
    
					this.form.fpNum = o.value.replace(inputRule , '');
				})
			},

1.只能输入数字

const inputRule = /[^\d]/g		

2.只能输入字母

const inputRule = /[^a-zA-Z]/g		

3.只能输入数字和字母

const inputRule =/[\W]/g

4.只能输入小写字母

const inputRule =/[^a-z]/g

5.只能输入大写字母

const inputRule =/[^A-Z]/g

6.只能输入数字和字母和下划线

const inputRule =/[^\w_]/g //下划线也可以改成%

7.只能输入中文

const inputRule =/[^\u4E00-\u9FA5]/g

8.只能输入数字和小数点

const inputRule =/[^\d.]/g

希望对大家有些帮助。

猜你喜欢

转载自blog.csdn.net/x_XDGS/article/details/120996210