On Mon, 27 Jan 2003 13:25:40 -0000, in gradwell.lists.cfdeveloper-dev
you wrote:

>We're doing a postcode lookup to autofill an address, but we need
>something to verify that a postcode is at least _syntactically_ valid if
>for some reason it's not in the PAF database. 

/me notices that tim cannot be bothered to check out his email archive
for messages I sent him before:

This is the regexp used by the .UK domain registry for the postcode
check (in Perl notation):

        /^[A-Z]{1,2}\d{1,2}[A-Z]? \d[A-Z]{2}$/

Admittedly this regexp would be more precise:


/^(?:(?:E1|EC[1-4]|SW1|W1|WC[12])[ABEHMNPRVWXY]|[A-Z]{1,2}\d{1,2})
\d[A-Z]{2}$/

. . . but only marginally so, and could cause problems if additional
postcodes become unexpectedly `subregioned'.

(Yes these regexps do miss out GIR 0AA and SAN TA1 but to date no one
has insisted upon using Girobank's processing centre or Santa Claus as
a contact.)

Apparently... full world post code syntax is given here:
http://www.magma.ca/~djcl/postcd.txt

According to that, the valid codes are given by:

United Kingdom
@# #@@    [postfix]
@#@ #@@   [postfix]
@## #@@   [postfix]
@@# #@@   [postfix]
@@@ #@@   [postfix]
@@## #@@  [postfix]
@@#@ #@@  [postfix]
@@@ #@@   [postfix]

another way of looking at the UK post code syntax is to say:


    post-code = left SPACE right / "GIR 0AA" / "SAN TA1"
    left = area district [sub-district]
    area = LETTER [LETTER] ; 124 legal cases, listed on the page
          ; <http://www.davros.org/postcodes/ukformat.html>
          ; or the special cases "FX" (testing) and "AM" (Ambridge).
    district = "0" / NONZERO [DIGIT]
    sub-district = SLETTER ; only used in EC1-4, SW1, W1, WC1, and WC2
    right = DIGIT RLETTER RLETTER

    DIGIT = "0" / NONZERO
    NONZERO = "1" / "2" / ... / "9"
    LETTER = "A" / ... / "Z"
    SLETTER = "A" / "B" / "E" / "H" / "M" / "N" / "P" / "R" /"V" / "W"
/ "X" / "Y"
    RLETTER = "A" / "B" / "D" / "E" / "F" / "G" / "H" / "J" / "L" /
"N" / "P" / "Q" / "R" / "S" / "T" / "U" / "W" / "X" / "Y" / "Z"


peter

-- 
peter gradwell. gradwell dot com Ltd. http://www.gradwell.com/
engineering & hosting services for email, web and usenet 

--
** Archive: http://www.mail-archive.com/dev%40lists.cfdeveloper.co.uk/

To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
For human help, e-mail: [EMAIL PROTECTED]

Reply via email to