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
Try this, it's working for me:
Why not use EF6 attribute based e-mail validation?
As you can see above, Regex validation for e-mail always has some hole in it. If you are using EF6 data annotations, you can easily achieve reliable and stronger e-mail validation with EmailAddress data annotation attribute available for that. I had to remove the regex validation I used before for e-mail when I got mobile device specific regex failure on e-mail input field. When the data annotation attribute used for e-mail validation, the issue on mobile was resolved.
TLD's like .museum aren't matched this way, and there are a few other long TLD's. Also, you can validate email addresses using the MailAddress class as Microsoft explains here in a note:
This saves you a lot af headaches because you don't have to write (or try to understand someone else's) regex.
This one prevents invalid emails mentioned by others in the comments:
It also prevents emails with double dots:
Try testing it with as many invalid email addresses as you can find.
See validate email address using regular expression in C#.
Just let me know IF it doesn't work :)
Try this on for size: