using System.Text.RegularExpressions;
public static void Main()
Console.WriteLine(ValidatePostcode("IP21 4AN").ToString());
private static bool ValidatePostcode(string postCode)
if (string.IsNullOrEmpty(postCode)) return false;
var regexPostCode = @"^([Gg][Ii][Rr]0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([AZa-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z]))))\\s?[0-9][A-Za-z]{2})$";
var reg = new Regex(Regex.Unescape(regexPostCode), RegexOptions.IgnoreCase);
if (!reg.IsMatch(postCode))