Have searched high and low and have not found a solution that works. There are some proposed @ php.net - but none seem to have it in the bag - anyone solved this successfully?
| SitePoint Sponsor |
Have searched high and low and have not found a solution that works. There are some proposed @ php.net - but none seem to have it in the bag - anyone solved this successfully?
~The Artist Latterly Known as Crazy Hamster~
922ee590a26bd62eb9b33cf2877a00df
Currently delving into Django, GIT & CentOS
Do you want to check: postcode actually exists OR postcode format is correct?
Laws are like sausages. You have much more respect for them if you haven't actually seen how they're made.
http://www.webamoeba.co.uk
Really the format, but it's those pesky London jobs that throw everything to whack. If you know of any good (and pref cheap) online verification systems, I'm all ears!
~The Artist Latterly Known as Crazy Hamster~
922ee590a26bd62eb9b33cf2877a00df
Currently delving into Django, GIT & CentOS
I think it'd help if you told us what the format was![]()
- Nathan
Ah, therein lies the problem....
It's gonna take someone who is very familiar with the postcode system to crack this. It is not clear-cut at all - I was kinda hoping to find someone who'd done it before.
There is quite comprehensive discussion here: http://php.planetmirror.com/manual/en/function.ereg.php
While I do know that none of the proposed solutions seem to work, I don't have a clue how to go about fixing it!![]()
~The Artist Latterly Known as Crazy Hamster~
922ee590a26bd62eb9b33cf2877a00df
Currently delving into Django, GIT & CentOS



http://www.regxlib.com/REDetails.aspx?regexp_id=260
^([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$
just sling a \ (or is it /) at the start and end
or run a search there - one apparently conforms to some format .....
--------------------------
United Kingdom
@# #@@ [postfix]
@#@ #@@ [postfix]
@## #@@ [postfix]
@@# #@@ [postfix]
@@@ #@@ [postfix]
@@## #@@ [postfix]
@@#@ #@@ [postfix]
@@@ #@@ [postfix]
(codings vary in length, depending on the first part of the code)
The initial letters indicate the Postcode area. The Postcode area,
followed by a number and possibly another letter, makes up the first
part of the code called the outward code.
The numeric portion in the outward code may be from 0 to 99. CR0 and WC99
are two examples of this that are in use.
The known initial outward codes of type @#@ or @@#@ are: EC#@, WC#@,
SW1@ (SW1P only?), W1@.
@@@ #@@ is a unique code GIR 0AA for the Post office Giro bank.
High numbers, eg BS98, BS99, WC99 etc are generally used for bulk
mailers (catalogue companies etc.)
The second portion of the postal code provides granularity at least
down to individual streets. The digit in the second half may be 0.
Initial letter(s) indicate the Postcode area of the UK. A variable set of
letters and numbers follow.
Postcode Areas (i.e. the initial letters of a postal code):
AB Aberdeen LL Llandudno
AL St. Albans LN Lincoln
B Birmingham LS Leeds
BA Bath LU Luton
BB Blackburn M Manchester
BD Bradford ME Medway
BH Bournemouth MK Milton Keynes
BL Bolton ML Motherwell
BN Brighton N London North
BR Bromley NE Newcastle-upon-Tyne
BS Bristol NG Nottingham
BT Belfast NN Northampton
CA Carlisle NP Newport (Gwent)
CB Cambridge NR Norwich
CF Cardiff NW London North-West
CH Chester OL Oldham
CM Chelmsford OX Oxford
CO Colchester PA Paisley
CR Croydon PE Peterborough
CT Canterbury PH Perth
CV Coventry PL Plymouth
CW Crewe PO Portsmouth
DA Dartford PR Preston
DD Dundee RG Reading
DE Derby RH Redhill
DG Dumfries RM Romford
DH Durham S Sheffield
DL Darlington SA Swansea
DN Doncaster SE London South-East
DT Dorchester SG Stevenage
DY Dudley SK Stockport
E London East SL Slough
EC London East Central SM Sutton
EH Edinburgh SN Swindon
EN Enfield SO Southampton
EX Exeter SP Salisbury
FK Falkirk SR Sunderland
FY Blackpool (Fylde) SS Southend-on-Sea
G Glasgow ST Stoke-on-Trent
GI Giro Bank (special) SW London South-West
GL Gloucester SY Shrewsbury
GU Guildford TA Taunton
HA Harrow TD Galashiels
HD Huddersfield TF Telford
HG Harrogate TN Tonbridge
HP Hemel Hempstead TQ Torquay
HR Hereford TR Truro
HS Hebrides (see note below) TS Cleveland (Teesside)
HU Hull TW Twickenham
HX Halifax UB Southall (Uxbridge)
IG Ilford W London West
IP Ipswich WA Warrington
IV Inverness WC London West Central
KA Kilmarnock WD Watford
KT Kingston-upon-Thames WF Wakefield
KW Kirkwall (Orkney) WR Worcester
L Liverpool WS Walsall
LA Lancaster WV Wolverhampton
LD Llandrindod Wells YO York
LE Leicester ZE Lerwick (Shetland)
Special UK territories and Postcode area codes/formats:
GY# #@@ Guernsey
IM# #@@ Isle of Man
IM## #@@ Isle of Man
JE# #@@ Jersey
New area introduced in 1995: HS Hebrides (recoding of PA8#) because
of unacceptably high level of manual miscodes to PA8.
Stray Notes:
Alan Pritchard (2) - "I have come across a number of mnemonic and
'personalised' codes. I am still not sure whether these are deliberate
or coincidental. I have a list of them somewhere but from memory.
Kings College, Cambridge (which thinks a lot of itself): CB1 1ST.
Department of National Savings ... 1NS. British Telecom DH99 1BT, the
one I really liked of a hospital which was ... 1LL"
(1,2,3,8)
-------------------------------
from http://www.magma.ca/~djcl/postcd.txt
You may run into problems when dealing with armed forces postcodes based in Northern Ireland. They look something like "BFPO33".....



BFPO ## is worldwide btw, the acronym means British Forces Patrolling Overseas or somesuch - might be worth slinging a workaround into the regex though for them.
Bookmarks