I am new to using Regex and was struggling with a problem. I have got to a certain point and I am stuck, I can't figure out how to 'ignore' or not match a pin which has a line break in it which is causing the code to fail the test.
using System;
using System.Text.RegularExpressions;
public class Pin
{
public static bool ValidatePin(string pin){
string pattern = "^([0-9]{4}|[0-9]{6})$";
Regex reg = new Regex(pattern);
Match match = reg.Match(pin);
if (match.Success) {
return true;
} else {
return false;
}
I have the regular expression above, how would I implement it so that when it tries to match a pin with the line break it returns "FALSE". The failed test pin was: "1234\n".