use Exporter;
use Carp qw(carp cluck croak confess);
use File::CounterFile;
+use Locale::Country;
use DBIx::DBSchema;
use FS::UID qw(dbh checkruid swapuid getotaker datasrc driver_name);
my $phonen = $self->getfield($field);
if ( $phonen eq '' ) {
$self->setfield($field,'');
- } elsif ( $country eq 'US' ) {
+ } elsif ( $country eq 'US' || $country eq 'CA' ) {
$phonen =~ s/\D//g;
$phonen =~ /^(\d{3})(\d{3})(\d{4})(\d*)$/
or return "Illegal (phone) $field: ". $self->getfield($field);
$self->setfield($field,$phonen);
} else {
warn "don't know how to check phone numbers for country $country";
- return $self->ut_alphan($field);
+ return $self->ut_textn($field);
}
'';
}
'';
}
+=item ut_country COLUMN
+
+Check/untaint country codes. Country names are changed to codes, if possible -
+see L<Locale::Country>.
+
+=cut
+
+sub ut_country {
+ my( $self, $field ) = @_;
+ unless ( $self->getfield($field) =~ /^(\w\w)$/ ) {
+ if ( $self->getfield($field) =~ /^([\w \,\.\(\)\']+)$/
+ && country2code($1) ) {
+ $self->setfield($field,uc(country2code($1)));
+ }
+ }
+ $self->getfield($field) =~ /^(\w\w)$/
+ or return "Illegal (country) $field: ". $self->getfield($field);
+ $self->setfield($field,uc($1));
+ '';
+}
+
=item ut_anything COLUMN
Untaints arbitrary data. Be careful.
=head1 VERSION
-$Id: Record.pm,v 1.21 2001-08-11 05:50:52 ivan Exp $
+$Id: Record.pm,v 1.24 2001-08-19 00:48:49 ivan Exp $
=head1 BUGS