Fixed issue with validator for postcodes
This commit is contained in:
parent
e31ec73934
commit
286ecf11e1
3 changed files with 12 additions and 2 deletions
|
@ -6,6 +6,7 @@ use Geo::UK::Postcode;
|
|||
use Scalar::Util qw/ looks_like_number /;
|
||||
use File::Basename qw/ fileparse /;
|
||||
use DateTime::Format::Strptime;
|
||||
use Try::Tiny;
|
||||
|
||||
sub register {
|
||||
my ( $plugin, $app, $conf ) = @_;
|
||||
|
@ -27,7 +28,12 @@ sub register {
|
|||
|
||||
$app->validator->add_check( postcode => sub {
|
||||
my ( $validation, $name, $value ) = @_;
|
||||
return Geo::UK::Postcode->new( $value )->valid ? undef : 1;
|
||||
my $postcode;
|
||||
try {
|
||||
$postcode = Geo::UK::Postcode->new( $value );
|
||||
};
|
||||
return defined $postcode && $postcode->valid ? undef : 1;
|
||||
|
||||
});
|
||||
|
||||
$app->validator->add_check( number => sub {
|
||||
|
|
Reference in a new issue