email regex issue
Possible Duplicate:
What is the best regular expression for validating email addresses?
I have a regular expression that validates email addresses:
/^[^0-9][A-z0-9_]+([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/
It fails on these types though:
a.whatever@whatever.com
When the .
before the @
is preceded by a single character the validation fails. I'm new to regular expressions, can someone help me allow those types of email addresses?
Change the +
quantifier to *
:
/^[A-z_][A-z0-9_]*([.][A-z0-9_]+)*[@][A-z0-9_]+([.][A-z0-9_]+)*[.][A-z]{2,4}$/
-----------------^
Note: I also changed [^0-9]
to [A-z_]
, which makes more sense in terms of your rules.
上一篇: 电子邮件的正则表达式,它为什么不起作用?
下一篇: 电子邮件正则表达式问题