How to validate email addess in Windows Forms

Today I want to add validation for email address in a Windows Forms application. I searched google, but didn’t got any simple solution. Then I tried with ASP.Net regex validation control and took the validation expression from it used in RegEx class.

Here is code

static bool IsValidEmail(string Email)
{
Regex regex = new Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");
return regex.IsMatch(emailAddress);
}

Happy Coding [:)]

No related content found.

This entry was posted in .Net, .Net 3.0 / 3.5 and tagged , , , , . Bookmark the permalink.

0 Responses to How to validate email addess in Windows Forms

  1. jonathan parker says:

    hey thanks for the post, that was exactly what i needed this am…appreciate you saving me some time…have a great day!

  2. anuraj says:

    Welcome Jonathan Parker. Thank you for your comments.

  3. mrwilson1 says:

    Look up the built in filter_vars methods too, even easier


    $ip = filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);

    $email = filter_var($email, FILTER_VALIDATE_EMAIL);

    http://us2.php.net/filter_var

    more

    http://us3.php.net/manual/hu/ref.filter.php

    for php 5 and up.
    You can both validate and santize

  4. anuraj says:

    Sorry, I blogged about validate mail address using .Net. Not Php or Javascript

  5. mrwilson1 says:

    Im sorry, I guess I saw windows forms and without thinking thought of php.

    My apologies. Pls feel free to delete that post.

  6. anuraj says:

    it is okay buddy :)

Leave a Reply

Your email address will not be published. Required fields are marked *

*


*

You may use these HTML tags and attributes: <a href="" title="" rel=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>