Click here to Skip to main content
15,890,579 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to create other forms as childs for the mdi form??
how to validate email id and what is it's regular expression??
i have following code but showing error
C#
Regex regex = new Regex("^(a-z)$");
            if (regex.IsMatch(textBox11.Text))
            {
                errorProvider3.SetError(textBox1, String.Empty);
            }
            else
            {
                errorProvider3.SetError(textBox1,
                      "Only email id is allow here");
            }
Posted
Comments
Boipelo 3-Sep-13 14:35pm    
All questions were answered this week, browse the section. I will also try to get links for you...

1 solution

Whether you use a regular expression or the .NET Framework example, please remember that both check only the format of an email address.
They do not ascertain if the email address actually exists in a mailbox server.

C# Example
C#
public static bool isValidEmail(string inputEmail)
{
   string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
         @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
         @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$";
   Regex re = new Regex(strRegex);
   if (re.IsMatch(inputEmail))
    return (true);
   else
    return (false);
}

An article on email address format validation using a Regular Expression
How to Find or Validate an Email Address[^]

.NET Framework Example
This example uses the .NET MailAddress Class to validate the format of an email address.
C#
bool IsValidEmail(string email)
{
    try {
        var mail = new System.Net.Mail.MailAddress(email);
        return true;
    }
    catch {
        return false;
    }
}
 
Share this answer
 
v4
Comments
ridoy 3-Sep-13 15:57pm    
5ed!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900