CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Question Regular expressions, anyone?

    Anyone know how to build the pattern?
    I'm trying to validate an email address in the form of user@host. I don't even need the tld part (.com, .be, .net).

    I read the helpfile topic in that, which explains things, but when I try to match, it always returns true.

    This is the pattern I though it should be...
    [a-zA-Z0-9\-\._]+\@[a-zA-Z0-9\-\._]+

    the first part [a-zA-Z0-9\-._]+ would be the part before the @, containing at least 1 character from a-z, A-Z, 0-9, dash (\-), dot (\.) or underscore (_).
    the same goes for the last part.
    The middle is just an escaped @, to match the @ sign.

    The problem is that it matches any string that has at least one charecter before and after the @ sign, no matter what.

    I think I need an expression that only give these where all characters match.

    Examples of addresses with the value it should be, and what it gives me

    user@host : true, gives true
    user@host@host: false, gives true
    us#er@host: false, gives true
    @user.host: false, gives false


    Anyone know what expression I should use, and knows why that is?
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  2. #2
    Join Date
    Oct 2002
    Location
    Växjö, Sweden
    Posts
    225
    There are quite a few sites that discuss this if you search the web.... Here's one....

    Link

    ....or try this....

    "^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$"

    /Leyan

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured