I use this
@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$"
regexp to validate the email
([\w\.\-]+)
- this is for the first-level domain (many letters and numbers, also point and hyphen)
([\w\-]+)
- this is for second-level domain
((\.(\w){2,3})+)
- and this is for other level domains(from 3 to infinity) which includes a point and 2 or 3 literals
what's wrong with this regex?
EDIT:it doesn't match the "something@someth.ing" email
The following code is based on Microsoft's Data annotations implementation on github and I think it's the most complete validation for emails:
I think your caret and dollar sign are part of the problem You should also modify the regex a little, I use the next @"[ :]+([\w.-]+)@([\w-.])+((.(\w){2,3})+)"
Try the Following Code:
I found nice document on MSDN for it.
How to: Verify that Strings Are in Valid Email Format http://msdn.microsoft.com/en-us/library/01escwtf.aspx (check out that this code also supports the use of non-ASCII characters for Internet domain names.)
There are 2 implementation, for .Net 2.0/3.0 and for .Net 3.5 and higher.
the 2.0/3.0 version is:
My tests over this method give:
This is my favorite approach to this so far:
Then use the created string extension like: