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
It has taken many attempts to create an email validator which catches nearly all worldwide requirements for email.
Extension method you can call with:
Regex pattern string you can get by calling:
The Code (mostly comments):
This does not meet all of the requirements of RFCs 5321 and 5322, but it works with the following definitions.
Below is the code
I use the above code to validate the email address.
I've been using the Regex.IsMatch().
First of all you need to add the next statement:
Then the method looks like:
It's a private method because of my logic but you can put the method as static in another Layer such as "Utilities" and call it from where you need.
Visual studio had this for years.
Hope this helps!