Regex.IsMatch Method
using System; using System.Text.RegularExpressions; public class Example { public static void Main() { string[] partNumbers= { "1111-111-1111"}; string pattern = @"^[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, Regex.IsMatch(partNumber, pattern) ? "is" : "is not"); } }