I am new to c# and Ive come across something I can't fix.
situation
I am creating a windows form application using visual studio 2010 which has the option to validate an email address. I looked at tutorials on using RegularExpression
s and have came to this. I feel I'm missing something because every time I validate, it only sends the MessageBox.Show("Email invalid");
to the user.
code
private void validateBtn_Click(object sender, EventArgs e)
{
Regex email = new Regex("^[a-zA-Z0-9]{1-20}@[a-zA-Z0-9]{1-20}.[a-zA-Z]{2-3}$");
if (!email.IsMatch(emailTxt.Text))
{
MessageBox.Show("Email invalid");
}
else
MessageBox.Show("Email Valid");
}