uniapp input框校验数据格式,只能输入汉字/数字/字母等
input框常用的正则表达式
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
验证手机号是否正确var phone=15054054532;var strTemp = /^1[3|4|5|6|7|8|9][0-9]{9}$/;if(strTemp.test(phone)){console.log(“正确”)}else{uni.showToast({icon:‘none’,title:‘请输入正确的电话’});return false}
电话号码隐藏中间4位var phonenumber=15054054532;var reg = /^(\d{3})\d{4}(\d{4})$/;this.phonenum=phonenumber.replace(reg, “$1****$2”)
转载:感谢分享原文链接:https://blog.csdn.net/x_XDGS/article/details/120996210