Regular expression for email, why doesn't it work?
Possible Duplicate:
What is the best regular expression for validating email addresses?
I've been trying to do some regex for email filtering.
Allowed
anystring@example.com
any.string@example.com
a@example.com
Not allowed
any.st.ring@example.com
.a@example.com
a.@example.com
@example.com
This one accepts all allowed... but also a.@example.com
^([a-zA-Z0-9]+[.]?){1,2}@([a-zA-Z0-9]+.)+(com)$
This one accepts all allowed... except a@example.com
!
Added [^.]
before @
^([a-zA-Z0-9]+[.]?){1,2}[^.]@([a-zA-Z0-9]+.)+(com)$
What am I missing here?
^[a-zA-Z0-9]+(.[a-zA-Z0-9]+)?@([a-zA-Z0-9]+.)+com$
will accept your 'allowed' emails and reject the others.
Naturally, that will not match all generally valid emails. See http://www.regular-expressions.info/email.html for a discussion on email regular expressions.
链接地址: http://www.djcxy.com/p/92824.html上一篇: 使用正则表达式在C#中编辑字符串
下一篇: 电子邮件的正则表达式,它为什么不起作用?