RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find UK postcode (matching caps only)
Expression
(^BFPO\s*[0-9]{1,4})|(^GIR\s*0AA$)|(ASCN|BBND|BIQQ|FIQQ|PCRN|SIQQ|STHL|TDCU\s*1ZZ)|(^(A[BL]|B[ABDHLNRST]?|C[ABFHMORTVW]|D[ADEGHLNTY]|E[CHNX]?|F[KY]|G[LUY]?|H[ADGPRSUX]|I[GMPV]|JE|K[ATWY]|L[ADELNSU]?|M[EKL]?|N[EGNPRW]?|O[LX]|P[AEHLOR]|R[GHM|S[AEGK-PRSTWY]?|Y[ADFNQRSW|UB|W[A-DFGHJKMNR-W]?|[YO]|[ZE])[1-9][0-9]?[ABEHMNPRVWXY]?\s*[0-9][ABD-HJLNP-UW-Z]{2}$)
Description
This is my combination of other UK postcode examples to date in this library. This is similar to Howard Richards’s solution in that it only permits valid combinations of letters, e.g. BN works, BM does not. The space(s) are optional, the string to match should be in upper case. On top of that, this solution allows BFPO (http://www.bfpo.mod.uk/bfponumbers_ships.htm) and Overseas Territories Postcodes (http://en.wikipedia.org/wiki/UK_postcodes) Please let me know if you have any suggetion to improve this!
Matches
BHPO 111 | GIR 0AA | SW1 1ZZ | BT1 3RT
Non-Matches
SW1 1ZZ1 | BT01 3RT
Author Rating: Not yet rated. Dmitri Rechetilov
Source
Your Rating
Bad Good

Enter New Comment

Title

Name

Comment

Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Copyright © 2001-2025, RegexAdvice.com | ASP.NET Tutorials