-4

i need to know how to validate e-mail address in C#. am using a textBox to type the e-mail address and using "Submit" button to go the other form. before go to the next form it should be validate as an e-mail address.

thank you.

1 Answers1

0

Try this method.

public bool IsValid(string emailaddress)
{
    try
    {
        MailAddress m = new MailAddress(emailaddress);

        return true;
    }
    catch (FormatException)
    {
        return false;
    }
}
cKNet
  • 635
  • 1
  • 10
  • 22
  • If you check this link: http://stackoverflow.com/questions/5342375/c-sharp-regex-email-validation you'll that this is not a good way. –  Oct 05 '14 at 10:15
  • didn't work 'IsValid' – Kusal Arunoda Oct 07 '14 at 04:58
  • @Hypenate To be fair, that's probably where they copied the answer from in the first place, not bothering to read why it's horribly wrong. ;) – J. Steen Feb 02 '15 at 08:12