Skip to main content

Posts

Showing posts from March, 2020

.Net C# match a UK postcode with a regular expression

UK postcode Validation in C# [ RegularExpression (@" ^(([a-zA-Z]{1,2}[0-9][A-Z0-9]?|ASCN|STHL|TDCU|BBND|[BFS]IQQ|PCRN|TKCA) ?[0-9][a-zA-Z]{2}|BFPO ?[0-9]{1,4}|(KY[0-9]|MSR|VG|AI)[ -]?[0-9]{4}|[a-zA-Z]{2} ?[0-9]{2}|GE ?CX|GIR ?0A{2}|SAN ?TA1)$ ", ErrorMessage = "Invalid Post Code.")] public string PostCode { get; set; } Refer -  https://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom