-2

I Build some simple code to fill the field like a forms. I put email input and i want to validate and if mail address was correct the code was allow to another action.

Console.Write("Enter Your Email : "); string acmail = Console.ReadLine();

validate the "acmail" it's a valid email adress or not

Midhushan
  • 15
  • 9
  • 2
    Could you share your code to see where are you solving this and what is the problem you face? – AndrasCsanyi Feb 13 '20 at 09:52
  • 1
    Look at [MailAddress Class](https://learn.microsoft.com/en-us/dotnet/api/system.net.mail.mailaddress?redirectedfrom=MSDN&view=netframework-4.8) – BWA Feb 13 '20 at 09:54
  • Have a look [here](https://stackoverflow.com/questions/16167983/best-regular-expression-for-email-validation-in-c-sharp) – Md Farid Uddin Kiron Feb 13 '20 at 09:55
  • check here this topic https://stackoverflow.com/questions/5342375/regex-email-validation – dimmits Feb 13 '20 at 09:55
  • Does this answer your question? [C# code to validate email address](https://stackoverflow.com/questions/1365407/c-sharp-code-to-validate-email-address) – Uzair Feb 13 '20 at 09:56
  • A lot of suggestions in this thread but I suggest reading [this instead](https://learn.microsoft.com/en-us/dotnet/standard/base-types/how-to-verify-that-strings-are-in-valid-email-format?redirectedfrom=MSDN). – Koray Elbek Feb 13 '20 at 09:57
  • To anyone who wants to validate a mail address with RegEx : Good luck. – Cid Feb 13 '20 at 09:58

1 Answers1

0
using System;
using System.Collections.Generic;

class Demo {
   static void Main() {
      string val;

      bool validEmail = false;

      Console.Write("Enter Email: ");
      val = Console.ReadLine();

      int stringSplitCount = val.Split('@').Length;

      if(stringSplitCount > 1 && stringSplitCount <= 2) // should only have one @ symbol
        {
           stringSplitCount = val.Split('.').Length;

           if(stringSplitCount > 1)  // should have at least one . (dot)
             validEmail = true
        }

      val += (validEmail ? " is valid" ; "is invalid");

      Console.WriteLine("Your input: {0}", val);

   }
}
mds731
  • 56
  • 6