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
  • 44,811
  • 17
  • 103
  • 137
Piotr P
  • 294
  • 1
  • 4
  • 12

0 Answers0