[ic] postcode field in state database
Jeff Fearn
jefffearn at gmail.com
Tue Apr 12 02:46:28 EDT 2005
Hi, I have been looking in to internationalising validation of
postcodes and states. Is the states database used for anything? I have
grepped through the code and not found anything using it.
I am specifically interested in the current use of the postcode field
in the state database. I have started using it to hold regular
expressions to validate postcodes against. I did have to enlarge
postcode to 32 chars to fit the Canadian re's.
i.e
00047 01 CA ON Ontario [KLMNP]\d[A-Za-z] \d[A-Za-z]\d
00328 02 AU QLD Queensland [4|9]\d\d\d
00150 00 US ME Maine ddddd(?:-?dddd)?
I then modified Order.pm to check the state & postcode using the modified table.
sub _multizip {
my($ref,$var,$val) = @_;
$val =~ s/^\s+//;
my $error;
my $cval = _get_cval($ref, $var);
my $state = _get_sval($ref, $var);
my $sql = "select postcode from state where state.country = '$cval'
and state.state = '$state'";
my $db = ::database_exists_ref('state');
my $results = $db->query({ sql => $sql, hashref => 'results' });
# postcode is a regular expression
if($results->[0]->{postcode} && ($val !~ m/^($results->[0]->{postcode})$/)){
return(undef, $var, "$val is not a valid postcode in state $state
for country $cval");
}
.... sip existing code...
sub _multistate {
my($ref,$var,$val) = @_;
my $error;
my $cval = _get_cval($ref, $var);
my $sql = "select count(*) as count from state where state.country =
'$cval' and state.state = '$val'";
my $db = ::database_exists_ref('state');
my $results = $db->query({ sql => $sql, hashref => 'results' });
# We have 0 or more than 1 match
if($results->[0]->{count} == 0){
# Only bail if this country has some data in state table
$sql = "select count(*) as count from state where state.country = '$cval'";
my $results_2 = $db->query({ sql => $sql, hashref => 'results_2' });
if($results_2->[0]->{count}){
return(undef, $var, "$val is not a valid state for country $cval");
}
}
.... sip existing code...
Can anyone see this breaking any exisiting or planned future use of
the state.postcode field?
Thanks, Jeff.
More information about the interchange-users
mailing list