Home > Archive > PHP Language > June 2007 > UK postal code fields
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
UK postal code fields
|
|
| cluthz 2007-05-18, 9:57 pm |
| Hi there,
I have a php / mysql application where I have to change the mysql postcode
field from being one field to two fields (for the first page and second part
of the post code).
In the database abuot 80% of fields have been entered in a good format
having a space between the two sections.
I'm going to write a script that will search for this space and divide all
existing postcodes at the the point where this space occurs. Where there is
no space in a postcode field. I'm just going to cut the postcode at the
fourth character. Therefore anything past the fourth character will go into
the second part of the field.
I thought before i go implementing this. Maybe someone has done it already,
or even knows of a webservice or something that exists that will do it with
better accuracy then I can.
A list of all valid postcodes (first part) would be useful for example as I
could compare each postcode to this list.
Any suggestions most welcome.
Thanks in advance
| |
| leader@congress.hotmail.com 2007-05-19, 3:58 am |
| On Fri, 18 May 2007 18:04:25 GMT, "cluthz" <WHATEEVVEERR@by.co.uk>
wrote:
>Hi there,
>
>I have a php / mysql application where I have to change the mysql postcode
>field from being one field to two fields (for the first page and second part
>of the post code).
>
>In the database abuot 80% of fields have been entered in a good format
>having a space between the two sections.
>
>I'm going to write a script that will search for this space and divide all
>existing postcodes at the the point where this space occurs. Where there is
>no space in a postcode field. I'm just going to cut the postcode at the
>fourth character. Therefore anything past the fourth character will go into
>the second part of the field.
>
>I thought before i go implementing this. Maybe someone has done it already,
>or even knows of a webservice or something that exists that will do it with
>better accuracy then I can.
>
>A list of all valid postcodes (first part) would be useful for example as I
>could compare each postcode to this list.
>
>Any suggestions most welcome.
>
>Thanks in advance
>
One of the gurus around here, some months ago, turned out to be an
expert in all this; your hope must be he reads your post (and mine!).
I'm having my own problems with the UK postcodes at present and might
add a couple of pointers -
1 - keep in mind that some (Central London only) postcodes can stretch
to, say, SW1A 1AA, and -
2 - some cities (Birmingham, Glasgow, Manchester, Liverpool,
Sheffield) have just the one starting letter (which can mess up your
sorts - G1 1AA, G41 1AA, etc).
As for your list, go see -
http://www.postcode-ads.co.uk/s/index.htm
Presumably the splitting is a prelude to sorts of all kinds. Unless
you stick a [space] before any single-digit area (e.g. convert G1 1AA
to G 1 1AA) you'll have more problems. I suggest you might avoid
problems in the future by manipulating any new input, adding spaces
appropriately.
| |
| murfitUK 2007-05-19, 7:57 am |
| I found this that might be helpful. There is a zip with a few files that
you may be able to inspect and there are links to the official postcode
standards.
http://www.braemoor.co.uk/software/postcodes.shtml
Might be worth a look.
<leader@congress.hotmail.com> wrote in message
news:l2us43pv9fn8ppr9icnjt022q6474quvfg@
4ax.com...
> On Fri, 18 May 2007 18:04:25 GMT, "cluthz" <WHATEEVVEERR@by.co.uk>
> wrote:
>
>
> One of the gurus around here, some months ago, turned out to be an
> expert in all this; your hope must be he reads your post (and mine!).
>
> I'm having my own problems with the UK postcodes at present and might
> add a couple of pointers -
> 1 - keep in mind that some (Central London only) postcodes can stretch
> to, say, SW1A 1AA, and -
> 2 - some cities (Birmingham, Glasgow, Manchester, Liverpool,
> Sheffield) have just the one starting letter (which can mess up your
> sorts - G1 1AA, G41 1AA, etc).
>
> As for your list, go see -
> http://www.postcode-ads.co.uk/s/index.htm
>
> Presumably the splitting is a prelude to sorts of all kinds. Unless
> you stick a [space] before any single-digit area (e.g. convert G1 1AA
> to G 1 1AA) you'll have more problems. I suggest you might avoid
> problems in the future by manipulating any new input, adding spaces
> appropriately.
>
| |
| Richard 2007-05-20, 10:00 pm |
|
"cluthz" <WHATEEVVEERR@by.co.uk> wrote in message
news:JUl3i.21627$Ro3.5590@text.news.blueyonder.co.uk...
> Hi there,
>
> I have a php / mysql application where I have to change the mysql postcode
> field from being one field to two fields (for the first page and second
> part of the post code).
>
> In the database abuot 80% of fields have been entered in a good format
> having a space between the two sections.
>
> I'm going to write a script that will search for this space and divide all
> existing postcodes at the the point where this space occurs. Where there
> is no space in a postcode field. I'm just going to cut the postcode at the
> fourth character. Therefore anything past the fourth character will go
> into the second part of the field.
I would use a different splitting logic.
UK postcodes, from what I've seen, are in the form A[A]n[y] nBB
ie. The initial character string is either 1 or 2 characters, and the
characters after the A[A] are either a 1 or 2 digit number, or a 1 digit
number + 1 letter.
So it's much easier to work back from the other end. Simply find the first
digit working in from the right hand side. This is the start of the second
half. Everything before this digit will be the first half.
Unless someone knows different.
| |
| cluthz 2007-05-21, 6:58 pm |
|
"Richard" <(none)> wrote in message
> Unless someone knows different.
Actually there are some central London postcodes which do not quite fit that
format I believe.
for example I thin there are things like
W1K
and other variations such as
W1K2
But yes once I establish the full range I can perhaps do something like you
suggest.
| |
| cluthz 2007-05-21, 6:58 pm |
|
>
> As for your list, go see -
> http://www.postcode-ads.co.uk/s/index.htm
>
> Presumably the splitting is a prelude to sorts of all kinds. Unless
> you stick a [space] before any single-digit area (e.g. convert G1 1AA
> to G 1 1AA) you'll have more problems. I suggest you might avoid
> problems in the future by manipulating any new input, adding spaces
> appropriately.
Thanks for input. Actually splitting of postcodes is for searches. We often
need to search people by area and currently the results do not always give
what you want.
for example, if we want people with postcodes W1 and W12, because this
search includes all postcodes beginning with W1, it also returns all the
W11's, W13's, etc.
This is not desirable. It is unlikely we will ever need to search on an
actual full postcode.
Therefore the first part is important. Having it as a single field, we can
search on actual match, rather then the first part.
Sorting of postcodes is not particularly a factor in our application.
Thanks for input
| |
| Ian Hobson 2007-05-24, 6:59 pm |
| Richard wrote:
> "cluthz" <WHATEEVVEERR@by.co.uk> wrote in message
> news:JUl3i.21627$Ro3.5590@text.news.blueyonder.co.uk...
>
> I would use a different splitting logic.
>
> UK postcodes, from what I've seen, are in the form A[A]n[y] nBB
>
> ie. The initial character string is either 1 or 2 characters, and the
> characters after the A[A] are either a 1 or 2 digit number, or a 1 digit
> number + 1 letter.
>
> So it's much easier to work back from the other end. Simply find the first
> digit working in from the right hand side. This is the start of the second
> half. Everything before this digit will be the first half.
>
> Unless someone knows different.
>
>
I can confirm you are correct.
If the code you have, does not end with two letters, you only have the
leading part.
The OP will need to remove punctuation, convert to upper case, and then
split as you describe. If he then places the first part in the leading
positions of a 8 character field (initialised to spaces), and any second
part in the last 3 positions, he will have a correctly formatted postcode.
If the last three positions are replaced with ??? if missing, he has a
simple regex to match partial postcodes that will NOT confuse LS1 with
LS10! "LS1--???" does not match "LS10-???" ("-" = space).
Regards
Ian
| |
|
|
|
|
|