Thursday 12 July 2007

Postcode Validation Regex

Validating postcodes in .Net has a couple gotcha's. The default behaviour for the RegularExpressionValidator is to perform case sensitive validation so I've modified a regex by Chris Applegate to suit my needs.
([Gg][Ii][Rr] 0[Aa][Aa]
|[A-Pa-pR-Ur-uWwYyZz][A-Ha-hK-Yk-y0-9][A-Ha-hJjKkSsTtUuWw0-9]?
[AaBbEeHhMmNnPpRrVvWwXxYy0-9]?
\s[0-9][AaBbD-Hd-hJjLlN-Un-uW-Zw-z]{2})