Home > .Net, .Net 3.0 / 3.5 > How to validate email addess in Windows Forms

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 [:)]

  1. jonathan parker
    March 26th, 2009 at 10:09 | #1

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

  2. March 27th, 2009 at 10:44 | #2

    Welcome Jonathan Parker. Thank you for your comments.

  3. mrwilson1
    April 23rd, 2009 at 01:23 | #3

    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. April 27th, 2009 at 18:46 | #4

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

  5. mrwilson1
    April 27th, 2009 at 21:15 | #5

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

    My apologies. Pls feel free to delete that post.

  6. April 30th, 2009 at 06:57 | #6

    it is okay buddy :)

  1. No trackbacks yet.