2

I want to make regular expresion that will only accept string that are 4 or 6 digit long, and won`t accept any other characters.

I have code like this:

public static bool ValidatePin(string pin)
{
    Regex rx = new Regex(@"(^[0-9]{4}$)|(^[0-9]{6}$)");
    return rx.IsMatch(pin);
}

Prety simple, but when I call:

Console.WriteLine(Kata.ValidatePin("1246\n"));

It returns true, it seems to not omit special character \n. What can I do to solve this problem?

fubo
  • 39,783
  • 16
  • 92
  • 127
Piotr P
  • 188
  • 1
  • 10

0 Answers0