I need to validate a email address the best way, and I need to include some danish characters:
Æ Ø Å开发者_运维问答
æ ø å
My current regex is:
\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
How to incorporate the extra letters, and is there any optimizing that can be done to ensure the best handling of the e-mail address?
Email address validation is hard with regular expressions.
A simple version could be:
^[ÆØÅæøåA-Za-z0-9._%+-]+@(?:[ÆØÅæøåA-Za-z0-9-]+\.)+[A-Za-z]{2,6}$
but this will fail on some valid addresses like Tim\ O'Reilly@microsoft.com
or me@1.2.3.4
, and match lots of invalid addresses like here@there.where
.
In any way, you have to send an e-mail to it and get a response before you really know whether an address is valid or not.
精彩评论