Merge branch 'TBSliver/Postcode-Validation-Fix' into development

This commit is contained in:
Tom Bloor 2017-07-25 17:07:36 +01:00
commit 4f72b454bc
2 changed files with 3 additions and 10 deletions

View file

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

View file

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