[ic] postcode field in state database

Duane Hinkley duane at downhomewebdesign.com
Tue Apr 12 07:43:25 EDT 2005


Jeff Fearn wrote:

>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.
>_______________________________________________
>interchange-users mailing list
>interchange-users at icdevgroup.org
>http://www.icdevgroup.org/mailman/listinfo/interchange-users
>
>  
>
Jeff,

That's a great idea.  I've been trying to figure out how to validate zip 
codes for other countries.  I'm no international zip code expert, but it 
might be a good idea to include the same thing for the country table.

This sounds like a good thing to add to the Interchange core.  I know I 
have clients that have been fighting shipment problems to addresses with 
bad international zip codes.

-- 

Sincerely,

Duane Hinkley
Down Home Web Design, Inc.
(208) 424-0572 Fax(208) 587-0738

duane at downhomewebdesign.com
www.downhomewebdesign.com



More information about the interchange-users mailing list