CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Regex.IsMatch is not working

  1. #1
    Join Date
    Apr 2014
    Posts
    28

    Regex.IsMatch is not working

    EDIT: SCRATCH THAT! I had the arguments backwards!

    This may be more of a regex question than a c# question. I'm learning regex.
    Code:
    using System.Text.RegularExpressions;
    
    MyOutput.Text = Regex.IsMatch("^[a-zA-Z]{3}[0-9]{4}$", "abc1234").ToString();
    What I want is to verify via regex that the data is 3 letters, then 4 numbers, e.g. "abc1234". However, it continues to return false no matter what I input. What's wrong with this expression? Thanks.
    Last edited by SlowCoder74; September 8th, 2014 at 12:21 PM.

  2. #2
    Join Date
    Aug 2014
    Posts
    6

    Re: Regex.IsMatch is not working

    Correct is this way :

    Regex.IsMatch("abc1234", "^[a-zA-Z]{3}[0-9]{4}$").ToString();

    The first parameter is input, and the second parameter is pattern.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)