JavaScript电子邮件正则表达式 [英] Javascript email regex

查看:100
本文介绍了JavaScript电子邮件正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到过对电子邮件正则表达式的描述。

I've come across a description of a decent email regex.

/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/

但是我还想在电子邮件的第一部分添加一些标点符号,同时保留其余功能(例如,不再重复)。 )

But I would also like to include some punctuation characters into the first part of the email whilst retaining the rest of the functionality (such as no repeated .)

到目前为止,我得出的最好成绩是:

The best I have come up with so far is:

([\/!#$%&'*+-=?^_`{|}~]*\w+)([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,40})+$

但是这不允许在电子邮件的第一部分末尾使用标点符号。

But this will not allow punctuation at the end of the first part of the email.

我发现regex令人困惑,有人知道如何正确实现

I find regex so confusing, does anyone know how to properly implement this?

例如:

Yes email@domain.com
Yes firstname.lastname@domain.com
Yes email@subdomain.domain.com
Yes firstname+lastname@domain.com
Yes email@123.123.123.123
Yes email@[123.123.123.123]
Yes "email"@domain.com
Yes 1234567890@domain.com
Yes email@domain-one.com
Yes _______@domain.com
Yes email@domain.name
Yes email@domain.co.jp
Yes firstname-lastname@domain.com
No  plainaddress
No  #@%^%#$@#$@#.com
No  @domain.com
No  Joe Smith <email@domain.com>
No  email@domain@domain.com
No  .email@domain.com
No  email.@domain.com
No  email..email@domain.com
No  あいうえお@domain.com
No  email@domain.com (Joe Smith)
No  email@domain
No  email@-domain.com
No  email@domain.web


推荐答案

这是我最近的尝试,我认为是大致正确

This is my closest attempt now, I think it is roughly correct

^[a-zA-Z0-9_!#$%&‘*\=\+\/\?^{|}~]+([\.-]?[a-zA-Z0-9_!#$%&‘*\=\+\/\?^{|}~]+)*@\w+([\.-]?\w+)*(\.\w{2,50})+$

这篇关于JavaScript电子邮件正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆