电子邮件的正则表达式 [英] Regular expression for email
问题描述
我正在使用此特定的正则表达式来检查电子邮件。
I am using this particular regular expression for checking emails.
"^[A-Za-z0-9](([a-zA-Z0-9,=\.!\-#|\$%\^&\*\+/\?_`\{\}~]+)*)@(?:[0-9a-zA-Z-]+\.)+[a-zA-Z]{2,9}$"
我遇到的问题是,这允许在 @符号前加句号。
可以通过任何方式对此表达式进行修改,以使这种情况不会发生,但仍保留所有其他条件。
The issue I have is that, this allows periods before the "@" symbol. Is there any way this expression be modified so that this does not happen, yet all other conditions are maintained.
a。@ b.com应该无效
a.@b.com should be invalid
预先感谢
-Rollin
Thanks in advance -Rollin
推荐答案
您可以将 [^ \。]
放在 @
之前,以便允许除点以外的任何字符
you could put [^\.]
before the @
so that it will allow any character except the dot
当然这可能不是您想要的,因此您可以在其中放入带有任何合法字符的 []
of course this is probably not what you want, so you could just put a []
with any legal characters in it
以防万一某人只有一个字符的电子邮件名(我的意思是 @
之前的部分),您可能需要使用 |
just in case someone has a email name (i mean the part before the @
) that is just 1 character, you might need to get creative with the |
这篇关于电子邮件的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!