JS 正则验证

Email验证

let Email = '[email protected]'
let reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/
if (reg.test(Email) {
  console.log('true')
} else {
  console.log('false')
}

手机号码验证

let phoneNumber = '18200001111'
let reg = /^1(3|4|5|6|7|8|9})\d{9}$/
if (reg.test(phoneNumber) {
  console.log('true')
} else {
  console.log('false')
}

用户名验证

let username = 'abc234_'
let reg = /^[a-zA-Z0-9_]{1,}$/
if (reg.test(username) {
  console.log('true')
} else {
  console.log('false')
}

你可能感兴趣的:(JS 正则验证)