1, 只能输入手机号,并且以英文逗号隔开
oninput() {
this.checkMobile(this.phone)
},
checkMobile(str) {
var Tel = /^((\+?86)|(\(\+86\)))?\d{3,4}-\d{7,8}(-\d{3,4})?$/
var fu = /(((1[73584]\d{9}))\,){0,}((1[73584]\d{9}))$/
if (Tel.test(str) || fu.test(str)) {
//是手机
} else {
//匹配失败
this.$message.error('手机号格式不正确')
}
},
2, 验证 身份证号
var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
if(reg.test(this.idNumber) === false){
this.$toast('请输入正确的身份证号');
return false;
}
身份证号,生日 显示星号**** 代替
// 使用
this.changeIdCardIncludeStart(this.idNumber)
changeIdCardIncludeStart (cardId) {
const newStr = cardId.replace(/^(.{6})(?:\d+)(.{4})$/,"$1****$2");
return newStr;
},
3,校验 手机号
if(!/^1[123456789]{1}\d{9}$/gi.test(this.info.contactTel)){
uni.showToast({
title:'请检查手机号',
icon:'none'
})
return false;
}
4, 只能输入数字和小数点的正则
if((/[^\-?\d.]/g).test(this.money)){
uni.showToast({
title:'支付金额输入错误',
icon:'none'
})
return false;
}
<input type="text" autocomplete="off" id="price" autofocus="autofocus" onkeyup="value=value.replace(/[^\d^\.]+/g,'')">
onkeyup="value=value.replace(/[^\-?\d.]/g,'')" // 仅允许输入:正负小数。
<input type="text" autocomplete="off" id="price" autofocus="autofocus" onkeyup="value=value.replace(/[^\d^\.]+/g,'').replace('.','$#$').replace(/\./g,'').replace('$#$','.')">
// 仅允许输入一个小数点。