-3

I have a regular expression for validating e-mail addresses in JavaScript:

^(([\w]+(.[^<>()[]\.,;:\s@"]+)*)|(".+"))@(([[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}])|([0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3})|(([a-zA-Z-0-9]+.)+[a-zA-Z]{2,}))$

I need to convert it to C# format.
What are the changes needed on the above JS Regex?

4
  • stackoverflow.com/questions/8989081/… Commented Nov 27, 2018 at 12:40
  • you can use [DataType(DataType.EmailAddress)] for validating Commented Nov 27, 2018 at 12:41
  • check this link - stackoverflow.com/questions/16536061/… Commented Nov 27, 2018 at 12:46
  • Sameer Ahmed:No need to use data Annotations.Need the Exact Regex in C# Commented Nov 27, 2018 at 13:02

1 Answer 1

0

@"^[\w!#$%&'+-/=?\^_{|}~]+(\.[\w!#$%&'*+\-/=?\^_{|}~]+)" + "@" + @"((([-\w]+.)+[a-zA-Z]{2,4})|([([0-9]{1,3}.){3}[0-9]{1,3})]|(([0-9]{1,3}.){3}[0-9]{1,3}))$"

Got this regex perfectly suits my requirements. Which allows IP addresses with or without [] enclosed

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.