Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

email validation in a c# winforms application

Hi how can i validate email in c# winforms ?

like image 707
Nagu Avatar asked Jul 29 '09 10:07

Nagu


People also ask

What is the validation for email?

Email Validation is a procedure that verifies if an email address is deliverable and valid. It runs a swift process that catches typos, whether they are honest mistakes or purposeful misdirects. It also confirms if a particular email address exists with a reliable domain such as Gmail or Yahoo.

How do I validate an email format?

A valid email address consists of an email prefix and an email domain, both in acceptable formats. The prefix appears to the left of the @ symbol. The domain appears to the right of the @ symbol. For example, in the address [email protected], "example" is the email prefix, and "mail.com" is the email domain.

What is email validation and verification?

Email verification is the process that is used to verify the validity of an email address. It is a must to-do task while performing email marketing and it is also termed as email list cleaning and validation.


3 Answers

You can use Regular Expressions to validate Email addresses:

RegEx reg=new RegEx(@"^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$", RegexOptions.IgnoreCase); ///Object initialization for Regex 
if(reg.IsMatch("email string"))
    //valid email
like image 53
TheVillageIdiot Avatar answered Oct 28 '22 00:10

TheVillageIdiot


The best way would be to forward this validation task to .NET itself:

public bool IsValidEmailAddress (string email)
{
    try
    {
        MailAddress ma = new MailAddress (email);

        return true;
    }
   catch
   {
        return false;
   }
}

Granted, it will fire false positives on some technically valid email addresses (with non-latin characters, for example), but since it won't be able to send to those addresses anyway, you can as well filter them out from the start.

like image 9
User Avatar answered Oct 28 '22 00:10

User


This page has a good regular expression matching email addresses.

Remember this is only a formal check. To check whether an email address really exists, you have to send an actual email to the address and check the mail server's response.

And even if this succeeds, the SMTP server might be configured to ignore invalid recipient addresses.

like image 2
devio Avatar answered Oct 27 '22 23:10

devio