验证邮箱
let self = this
let regEmail= /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/
if (!regEmail.test(self.ruleForm.tourMail)) {
self.$message({
type: 'error',
message: '请填写正确的邮箱',
center: true
})
}
匹配非法字符
let regAccount = /[@#\$%\^&\*\s+]+/g
if (regAccount.test('dsa@ wdawd')) {
"请勿输入非法字符"
return false
}
匹配中文
let regAccountCN = /[\u4e00-\u9fa5]+/g
if (regAccount.test('你说呢')) {
"请勿输入中文"
return false
}
匹配电话号码,包括固定电话与手机号码
let regTelphone = /(^0\d{2,3}-\d{7,8}(-\d{1,6})?$)|(^0?1[34578]\d{9}$)/
input输入时限制只能输入数字和 -
<input type='text' onkeyup="(this.v=function(){this.value=this.value.replace(/[^0-9-]+/,'');}).call(this)" onblur="this.v();"/>
希望本文对你有所帮助!