Check if input in textbox is email

c#, winforms

Solution

Don't bother with Regex. It's a Bad Idea.

I normally never use exceptions to control flow in the program, but personally, in this instance, I prefer to let the experts who created the `MailAddress` class do the work for me:

try
{
    var test = new MailAddress("");
}
catch (FormatException ex)
{
    // wrong format for email
}

Problem

I am trying to validate if the userinput is an email adress (adding a member to database). The user will enter data in TextBox, when the validating event gets called; I want to check if the input is a valid email adress. So consisting of atleast an @ and a dot(.) in the string. Is there any way to do this through code, or perhaps with a Mask from the MaskedTextbox?

Original source

Related problems