Ask a questionAsk a question
 

AnswerValidatiom email

Answers

  • Thursday, August 24, 2006 12:34 PMcgrausModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    This is the regex for email addresses in expresso:

    ([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})

     

    So something like

    if (Regex.IsMatch(string, @"([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})"))

    will return true if string is an email address

    Don't forget to put using System.Text.RegularExpressions;

     

All Replies

  • Thursday, August 24, 2006 12:24 PMcgrausModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    What are you hoping to validate, an email *address*, or something else ? Regex to validate email addresses are pretty common, I think expresso even has one built in.

     

  • Thursday, August 24, 2006 12:30 PMLeandro Rodrigues Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I'm needing that when I client put or email in my form my system talk to me If or email is true else false. Only it!

    Thank you a lot! again

  • Thursday, August 24, 2006 12:34 PMcgrausModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    This is the regex for email addresses in expresso:

    ([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})

     

    So something like

    if (Regex.IsMatch(string, @"([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})"))

    will return true if string is an email address

    Don't forget to put using System.Text.RegularExpressions;

     

  • Friday, November 06, 2009 3:42 PMEfran Cobisi [cobisi.com] Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code
    I know I'm a bit in late with this message, but I'm posting it anyway for future readers who may find it useful.

    In my company we use EmailVerify.NET (http://www.emailverify.net), a Microsoft .NET component which supports e-mail syntax checking, domain MX test and mailbox validation too.
    E-mail validation up to the mailbox level is easy as writing the following code block:

    var verifier = new EmailVerifier();
    var result = verifier.Verify("me@example.com", VerificationLevel.Mailbox);
    
    if (result.IsSuccess)
    {
       // Go on, send the message
    }
    

    Additional code samples can be found here.
    From their home page:

    EmailVerify.NET is a powerful .NET component which verifies email addresses using various techniques, including:
    • Syntax verification, according to RFC 2821 and RFC 2822
    • MX record lookup
    • Disposable email address (DEA) validation
    • SMTP availability check
    • Mailbox existence check, with greylisting support
    • Catch-all test

    It is completely written in managed code (C#) and is compliant with the Common Language Specification (CLS), so it can be used with any other .NET language, including VB.NET, C++/CLI, J#, IronPython, IronRuby and F#.

    The price for this component is very small (less than 50 bucks) and their support is one of the greatest I've ever found for a small software company like they are.
    Hope this helps.