RE: [PHP] UK Postcode Reg Exp
| From: | James Lobley | Date: | Tue, 17 Feb 2004 17:37:44 +0000 |
| Subject: | RE: [PHP] UK Postcode Reg Exp | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-177987@lists.php.net to get a copy of this message | ||
Try this one:
$postcode2 = strtoupper(str_replace(chr(32),'',$postcode));
$pc_suffix = substr($postcode2,-3,3);
$pc_prefix = substr($postcode2,0,(strlen($postcode2)-3));
if (!preg_match('/(^[A-Z]{1,2}[0-9]{1,2}|^[A-Z]{1,2}[0-9]{1}[A-Z]{1})$/',$pc_prefix)
&& !preg_match('/^[0-9]{1}[ABD-HJLNP-UW-Z]{2}$/',$pc_suffix)) echo("Invalid
postcode!");
It seems to have been working nicely on all variants put through it over the past few months!
James
------------------------------------------------------------------------
I like nonsense ~ it wakes up the brain cells.
Fantasy is a necessary ingredient in living.
It's a way of looking at life through the wrong end of a telescope...
and that enables you to laugh at all of life's realities.
~ Theodor S. Geisel, a.k.a. "Dr. Seuss"
------------------------------------------------------------------------
-----Original Message-----
From: James Nunnerley [mailto:webmaster@jnsolutions.co.uk]
Sent: 17 February 2004 16:59
To: 'Shaun'; php-general@lists.php.net
Subject: RE: [PHP] UK Postcode Reg Exp
Hi Shaun,
Not that I know of - although I have looked at various things like this
myself. Would you be interested in a small open source project on this
subject?
I see you instigated the discussion on this earlier today. It might be
something worth putting on PEAR, and somehow linking it with the Royal
Mail Address search - assuming we can get through their login process!
Any thoughts?
James
webmaster@jnsolutions.co.uk
-----Original Message-----
From: Jay Blanchard [mailto:jay.blanchard@niicommunications.com]
Sent: 17 February 2004 16:55
To: Shaun; php-general@lists.php.net
Subject: RE: [PHP] UK Postcode Reg Exp
[snip]
Has anyone written a regular expression for validating a UK Postcode?
[/snip]
Nope, but I did write a love note to a French woman.
Sorry, couldn't resist. :) I'll be here all week.
Can you provide several examples and perhaps we could formulate one?
--
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