Wednesday, May 5, 2010

Validate contract in C# using REGEX

String strToTest;
String rePattern = "^[FGHJKMNQUVXZ][0-9]$";

Console.Write("Enter a String to Test for Contract:");
strToTest = Console.ReadLine();

Regex regexPattern = new Regex(rePattern);
Console.WriteLine(regexPattern.IsMatch(strToTest) == true ? "OK" : "KO");

strToTest = Console.ReadLine();

No comments: