Fede E.
Fede E.

Reputation: 1918

Issue with regex (3 capital letters proceeding with 4 numbers)

I have the following code, which should be passing the regex but it isn't, I'm missing something?

if (Regex.IsMatch("ABC1234", "/^[A-Z]{3}[0-9]{4}$"))
        {
            //Pasosed Regex
            Console.WriteLine("Pass");
        }
        else
        {
            Console.WriteLine("No Pass");
        }

Output: "No Pass"

Can Anyone help?

Upvotes: 0

Views: 32

Answers (1)

AndrewP
AndrewP

Reputation: 1618

Remove the / from your pattern and it should work.

Console.WriteLine(
    Regex.IsMatch("ABC1234", "^[A-Z]{3}[0-9]{4}$").ToString()
);
// True

Upvotes: 1

Related Questions