Regular expression for email [duplicate]
Possible Duplicate:
What is the best regular expression for validating email addresses?
I tried the reg expression
^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+
for the email validation.
Since I want the user to allow submitting even with the empty email address. So I changed the reg ex to
(^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+)?
But this expression accepts any email address without any validation.
Thanks Konerak!!!! I changed the expression to
^(([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+)?$
and this is working for me.
Welcome. http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html
How to: Verify That Strings Are in Valid E-Mail Format
A good bit of info on doing this is available at this page.
As that page will tell you, it's extremely difficult to pass any and all RFC822-compliant addresses with a regex. You need to ask yourself just how important this is to your application.
Personally I would recommend, if applicable, simply asking users to enter the email address twice and then confirm with a confirmation email. That way you don't run the risk of erroneously rejecting a valid email address (an extremely annoying situation for users which will likely lose your site some customers).
精彩评论