tags:

views:

43

answers:

1

Hello.

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?

+2  A: 

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'[email protected] or [email protected], and match lots of invalid addresses like [email protected].

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.

Tim Pietzcker