Indicates whether the regular expression specified in the Regex constructor finds a match in the input string.
using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string[] partNumbers= { "1234-111-1111", "A08Z-931-468A"};
Regex rgx = new Regex(@"^[a-zA-Z0-9]\d{2}[a-zA-Z0-9](-\d{3}){2}[A-Za-z0-9]$");
foreach (string partNumber in partNumbers)
Console.WriteLine("{0} {1} a valid part number.",
partNumber,
rgx.IsMatch(partNumber) ? "is" : "is not");
}
}
Related examples in the same category