On 1 Apr 2003 at 11:47, Jon Reades wrote:

> I'm doing a little UK address validation, and after looking around on 
> CPAN didn't come up with much except Reg::Common::zip, and that didn't 
> cover UK addresses (Damian, your name is on this Module, are you 
> listening? :) ).

Abigail is apparently maintaining the module now; ask him.

The version I got from CPAN had a start at UK postal codes, but they're 
commented out.

> there's the interesting additional fact that C I K M O V cannot be used 
> in the incode (the letters that come after the digit on the right-hand 
> side).
> 
> Of course, it doesn't tell me if this is a rule, or just a general 
> statement of fact, but that could presumably help in validating 
> addresses using a regex.

That's the rule used by Regexp::Common::zip. Observe:

# pattern name   => [qw /zip British/, "-sep= "],
#         create => sub {
#             my $sep     = $_ [1] -> {-sep};
# 
#             my $london  = '(?:EC[1-4]|WC[12]|S?W1)[A-Z]';
#             my $single  = '[BGLMS][0-9]{1,2}';
#             my $double  = '[A-Z]{2}[0-9]{1,2}';
# 
#             my $left    = "(?:$london|$single|$double)";
#             my $right   = '[0-9][ABD-HJLNP-UW-Z]{2}';
# 
#             "(?k:(?k:$left)(?k:$sep)(?k:$right))";
#         },
#         ;

I presume "?k:" gets translated into either "?:" or "" depending on 
whether the "keep" option is set or not. The rest should be fairly self-
explanatory.

I seem to recall that there were a couple of additional weird postal 
codes (from when Abigail asked on a newsgroup or mailing list 
somewhere)... if I think of it, I'll have a look at home where I saved 
a couple of interesting messages from that thread. On the other hand, 
they may not be of interest in the Real World.

Cheers,
Philip
-- 
Philip Newton <[EMAIL PROTECTED]>


Reply via email to