邮箱正则表达式

关于邮箱验证的正则表达式

关于直接使用正则表达式

isEmail = (e: string) => {
   return /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/.test(e)
}
if (!this.isEmail('email')) {
   console.log('不合法')
}

使用new RegExp()时\, 要变成\双斜线

const rePass = new RegExp('^([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\\_|\\.]?)*[a-zA-Z0-9]+\\.[a-zA-Z]{2,3}$', '');
const isPass = rePass.test(control.value);
if (isPass == false) {
     console.log('不合法')
}
posted @ 2020-06-02 17:40  Michelyuan  阅读(15381)  评论(0编辑  收藏  举报