-3

I'm currently building a system that requires the user to enter an email address and to ensure that they don't just enter in any random array of numbers and letters, I would like something to validate it so that '@' and '.com' are used and in the correct order when they try to submit their details to a SQL database built within VS 2013.

Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
  • Yes, it is emphatically "possible" to validate an email address using C#. As others have pointed out, there are many duplicate questions about this. But to answer your actual question: yes it is possible. Good luck. – samiles Feb 03 '17 at 10:37

1 Answers1

0

MSDN article How to: Verify that Strings Are in Valid Email Format gives following regular expressions to validate e-mail address:

bool IsValid = Regex.IsMatch(StrInTextControl,
      @"^(?("")("".+?(?<!\\)""@)|(([0-9a-z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-z])@))" +
      @"(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-z][-\w]*[0-9a-z]*\.)+[a-z0-9][\-a-z0-9]{0,22}[a-z0-9]))$",
              RegexOptions.IgnoreCase, TimeSpan.FromMilliseconds(250));
Alexei Levenkov
  • 98,904
  • 14
  • 127
  • 179
Anu Viswan
  • 17,797
  • 2
  • 22
  • 51
  • For future answers/questions please make sure to be very clear what code you wrote yourself and what code taken from other source (must provide clear link to original location for attribution). In this particular case answer is pointless as there is much better existing answer on SO (which you could have found and commented on the post instead). – Alexei Levenkov Feb 05 '17 at 07:01