vue, js 正则邮箱验证、匹配非法字符、匹配中文

验证邮箱
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
}
 
\s 表示空白字符。包括,空格,制表符
“ ”只表示空格。
\s+ 可匹配至少一个空白字符。
[ ]+ 只表示多个空格
 
匹配中文
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();"/>
 
希望本文对你有所帮助!
 
 

posted on 2018-06-29 10:54  王子乔  阅读(1923)  评论(0编辑  收藏  举报

导航