RFC822:使用正则表达式验证电子邮件地址 [英] RFC822: email address validation with regular expressions

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

问题描述

如您所知,这是我们验证电子邮件地址的方式:

as you know, this is how we validate an email address:

(?:(?:
)?[ 	])*(?:(?:(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)?[ 	]
)+||(?=[["()<>@,;:\".[]]))|"(?:[^"
\]|\.|(?:(?:
)?[ 	]))*"(?:(?:

)?[ 	])*)(?:.(?:(?:
)?[ 	])*(?:[^()<>@,;:\".[] 00-31]+(?:(?:(
?:
)?[ 	])+||(?=[["()<>@,;:\".[]]))|"(?:[^"
\]|\.|(?:(?:
)?[ 
	]))*"(?:(?:
)?[ 	])*))*@(?:(?:
)?[ 	])*(?:[^()<>@,;:\".[] 00-
31]+(?:(?:(?:
)?[ 	])+||(?=[["()<>@,;:\".[]]))|[([^[]
\]|\.)*
](?:(?:
)?[ 	])*)(?:.(?:(?:
)?[ 	])*(?:[^()<>@,;:\".[] 00-31]+
(?:(?:(?:
)?[ 	])+||(?=[["()<>@,;:\".[]]))|[([^[]
\]|\.)*](?:
(?:
)?[ 	])*))*|(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)?[ 	])+|
|(?=[["()<>@,;:\".[]]))|"(?:[^"
\]|\.|(?:(?:
)?[ 	]))*"(?:(?:
)
?[ 	])*)*<(?:(?:
)?[ 	])*(?:@(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
r
)?[ 	])+||(?=[["()<>@,;:\".[]]))|[([^[]
\]|\.)*](?:(?:
)?[
 	])*)(?:.(?:(?:
)?[ 	])*(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)
?[ 	])+||(?=[["()<>@,;:\".[]]))|[([^[]
\]|\.)*](?:(?:
)?[ 	]
)*))*(?:,@(?:(?:
)?[ 	])*(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?: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^[]
\]|\.)*](?:(?:
)?[ 	])*))*(?:,@(?:(?:
)?[
 	])*(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)?[ 	])+||(?=[["()<>@,
;:\".[]]))|[([^[]
\]|\.)*](?:(?:
)?[ 	])*)(?:.(?:(?:
)?[ 	]
)*(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)?[ 	])+||(?=[["()<>@,;:\
".[]]))|[([^[]
\]|\.)*](?:(?:
)?[ 	])*))*)*:(?:(?:
)?[ 	])*)?
(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)?[ 	])+||(?=[["()<>@,;:\".
[]]))|"(?:[^"
\]|\.|(?:(?:
)?[ 	]))*"(?:(?:
)?[ 	])*)(?:.(?:(?:

)?[ 	])*(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)?[ 	])+||(?=[[
"()<>@,;:\".[]]))|"(?:[^"
\]|\.|(?:(?:
)?[ 	]))*"(?:(?:
)?[ 	])
*))*@(?:(?:
)?[ 	])*(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)?[ 	])
+||(?=[["()<>@,;:\".[]]))|[([^[]
\]|\.)*](?:(?:
)?[ 	])*)(?:
.(?:(?:
)?[ 	])*(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)?[ 	])+|
|(?=[["()<>@,;:\".[]]))|[([^[]
\]|\.)*](?:(?:
)?[ 	])*))*>(?:(
?:
)?[ 	])*))*)?;s*)

你能向我解释一下这里发生了什么吗?

can you please explain to me what is going on here?

我们是否正在查看字符串并决定它是否是电子邮件地址?

are we looking at a string and deciding whether it is an email address?

你能不能至少解释一下第一行:

can you at least explain the first line:

(?:(?:
)?[ 	])*(?:(?:(?:[^()<>@,;:\".[] 00-31]+(?:(?:(?:
)?[ 	]

你能给我举一个很少见但有效的电子邮件地址的例子吗??

can you give me an example of an email address that is rarely seen, yet it is valid??

推荐答案

我认为你应该忘记这个.如果您想在正则表达式方面做得更好,那是一回事,而且可能有更好的学习方法.否则,验证电子邮件地址是一项极其复杂且容易出错的活动,我不知道有任何剪切和粘贴解决方案可以完全覆盖所有极端情况.沿着这条路走下去的是疯狂.如果您有 Internet 连接的应用程序,最好通过实际发送确认电子邮件来验证地址.

I think you should forget about this. If you're trying to be better at regular expressions, that is one thing, and there are probably better ways of learning. Otherwise, validating email addresses is an extremely complex and error-prone activity, and I'm not aware of any cut-and-paste solution that will completely cover all the corner cases. Down that path lies madness. If you have an Internet connected application, it's better to validate an address by actually sending a confirmation email.

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

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