RE: [PHP] Zip to postcode[Scanned]

2003-04-02 Thread Michael Egan
Andy,

There are some ready made scripts for dealing with UK post codes on the relevant page 
on the PHP site:

http://www.php.net/manual/en/function.ereg.php


HTH,

Michael Egan

-Original Message-
From: Andy [mailto:[EMAIL PROTECTED]
Sent: 02 April 2003 12:54
To: [EMAIL PROTECTED]
Subject: [PHP] Zip to postcode[Scanned]


Can someone please tell me how i change the following code:
if (!ereg(^[0-9]{5,5}(\-[0-9]{4,4})?$,$postcode))

to a UK postcode QQ1 1QQ
When i fill out the form it tells me that the postcode is not valid and i
think it is because it is in zip code format.

Thank you

Andy



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



re: [PHP] Zip to postcode

2003-04-02 Thread skate
sorry, don't have anything to add for code, but just a note to remember that UK post 
codes can also be in the form...

QQ11 1QQ
Q1 1QQ
Q11 1QQ
QQ1 1QQ

so it's a real pain to write an expression for this...

-skate-




Can someone please tell me how i change the following code:
if (!ereg(^[0-9]{5,5}(\-[0-9]{4,4})?$,$postcode))

to a UK postcode QQ1 1QQ
When i fill out the form it tells me that the postcode is not valid and i
think it is because it is in zip code format.

Thank you

Andy



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



re: [PHP] Zip to postcode

2003-04-02 Thread Peter Hicks

Don't forget some London postcodes are Q1Q QQQ!


Peter.


On Wed, 2 Apr 2003, skate wrote:

 sorry, don't have anything to add for code, but just a note to remember that UK post 
 codes can also be in the form...

 QQ11 1QQ
 Q1 1QQ
 Q11 1QQ
 QQ1 1QQ

 so it's a real pain to write an expression for this...

 -skate-




 Can someone please tell me how i change the following code:
 if (!ereg(^[0-9]{5,5}(\-[0-9]{4,4})?$,$postcode))

 to a UK postcode QQ1 1QQ
 When i fill out the form it tells me that the postcode is not valid and i
 think it is because it is in zip code format.

 Thank you

 Andy






-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Zip to postcode

2003-04-02 Thread William Bailey
Hi Andy,

The following function seems to work for me:

function split_postcode ($postcode) {
if(eregi('(^[A-Z]{1,2})([0-9|A-Z]{1,2}).*([0-9][A-Z]{2}$)', str_replace(' 
', '', $postcode), $parts)){
$outcode=strtoupper(sprintf('%s%s%s', $parts[1], @str_repeat(' ', 
4-strlen($parts[1])-strlen($parts[2])), $parts[2]));
$incode=strtoupper($parts[3]);
return array($outcode, $incode);
}else{
return False;
}
}

On Wednesday 02 April 2003 12:54, Andy wrote:
 Can someone please tell me how i change the following code:
 if (!ereg(^[0-9]{5,5}(\-[0-9]{4,4})?$,$postcode))

 to a UK postcode QQ1 1QQ
 When i fill out the form it tells me that the postcode is not valid and i
 think it is because it is in zip code format.

 Thank you

 Andy

-- 
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk
http://wb.pro-net.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] Zip to postcode[Scanned]

2003-04-02 Thread Ford, Mike [LSS]
 -Original Message-
 From: Michael Egan [mailto:[EMAIL PROTECTED]
 Sent: 02 April 2003 13:05
 
 There are some ready made scripts for dealing with UK post 
 codes on the relevant page on the PHP site:
 
 http://www.php.net/manual/en/function.ereg.php

And not one of them is 100% correct!!  This would be my stab:

preg_match('/^([A-Z]{1,2}([0-9]{1,2})|[0-9][A-Z])|GIR)'
   . ' ?[0-9][A-Z]{2}$/i', $postcode)

(I've divided the pattern in two here simply to avoid strange line wrapping!)

One of the user notes referred to says that postcodes are sometimes written with a 
space after the initial letters; although technically this is incorrect, adjusting to 
allow it would give:

preg_match('/^([A-Z]{1,2} ?([0-9]{1,2})|[0-9][A-Z])|GIR)'
   . ' ?[0-9][A-Z]{2}$/i', $postcode)

Another states that the set of letters in the last two positions is restricted -- I 
can't vouch for the accuracy of this, but if it's the case the match would become:

preg_match('/^([A-Z]{1,2} ?([0-9]{1,2})|[0-9][A-Z])|GIR)'
   . ' ?[0-9]}[ABD-HJLNP-UW-Z]{2}$/i', $postcode)

Finally, if you really, really want to accept only completely valid postcodes (not 
just validly formatted ones), you should get the full list of postcode area 
identifiers (the initial letter or two) and validate against those -- plus any local 
peculiarities that occur (for example, in my local postcode area, the final digit is 2 
in *all* cases).  (Well, I guess here we're getting into the realms of paying for the 
Royal Mail's postcode database!!)

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning  Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php