Change to underlying postcode regex for validation

This commit is contained in:
Tom Bloor 2017-07-25 17:07:15 +01:00
parent 9c7e9d325a
commit e2732a6a93
2 changed files with 3 additions and 10 deletions

View file

@ -4,7 +4,7 @@ requires 'Data::UUID';
requires 'Devel::Dwarn';
requires 'Mojo::JSON';
requires 'Email::Valid';
requires 'Geo::UK::Postcode';
requires 'Geo::UK::Postcode::Regex';
requires 'Authen::Passphrase::BlowfishCrypt';
requires 'Time::Fake';
requires 'Scalar::Util';

View file

@ -2,7 +2,7 @@ package Pear::LocalLoop::Plugin::Validators;
use Mojo::Base 'Mojolicious::Plugin';
use Email::Valid;
use Geo::UK::Postcode;
use Geo::UK::Postcode::Regex qw/ is_valid_pc /;
use Scalar::Util qw/ looks_like_number /;
use File::Basename qw/ fileparse /;
use DateTime::Format::Strptime;
@ -28,14 +28,7 @@ sub register {
$app->validator->add_check( postcode => sub {
my ( $validation, $name, $value ) = @_;
my $postcode;
try {
$postcode = Geo::UK::Postcode->new( $value );
};
return 1 unless defined( $postcode );
return 1 if $postcode->partial;
return undef if $postcode->valid;
return 1;
return is_valid_pc( $value ) ? undef : 1;
});
$app->validator->add_check( number => sub {