Introducing Radical.sh

Forget Code launches a powerful code generator for building API's

Validating Email using regular expressions in C#

  1. using System.Text;
  2. using System.Text.RegularExpressions;
  3.  
  4. string text = Console.ReadLine();
  5. string reg = @"^((([\w]+\.[\w]+)+)|([\w]+))@(([\w]+\.)+)([A-Za-z]{1,3})$";
  6.  
  7. if (Regex.IsMatch(text, reg))
  8. {
  9. Console.WriteLine("Email.");
  10. }
  11. else
  12. {
  13. Console.WriteLine("Not email.");
  14. }

Output:
sakfkgfc@kfseg.cic
Email
asfllsfcn
Not Email