|
Posted by Ian Hobson on 05/24/07 22:54
Richard wrote:
> "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.
>
>
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
Navigation:
[Reply to this message]
|