Fixed issue with postcode validator
This commit is contained in:
parent
aed22d1c98
commit
ae6884202a
2 changed files with 5 additions and 2 deletions
|
@ -32,7 +32,7 @@ sub register {
|
||||||
try {
|
try {
|
||||||
$postcode = Geo::UK::Postcode->new( $value );
|
$postcode = Geo::UK::Postcode->new( $value );
|
||||||
};
|
};
|
||||||
return defined $postcode && $postcode->valid ? undef : 1;
|
return defined( $postcode ) && ( $postcode->valid ) && ! ( $postcode->partial ) ? undef : 1;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,7 @@ my $invalid_email = 'test.example.com';
|
||||||
my $valid_postcode = 'WC1H 9EB';
|
my $valid_postcode = 'WC1H 9EB';
|
||||||
my $invalid_postcode = 'AB1 2CD';
|
my $invalid_postcode = 'AB1 2CD';
|
||||||
my $not_a_postcode = 'a';
|
my $not_a_postcode = 'a';
|
||||||
|
my $not_a_whole_postcode = 'LA1';
|
||||||
|
|
||||||
$validation->input({
|
$validation->input({
|
||||||
valid_email => $valid_email,
|
valid_email => $valid_email,
|
||||||
|
@ -22,6 +23,7 @@ $validation->input({
|
||||||
valid_postcode => $valid_postcode,
|
valid_postcode => $valid_postcode,
|
||||||
invalid_postcode => $invalid_postcode,
|
invalid_postcode => $invalid_postcode,
|
||||||
not_a_postcode => $not_a_postcode,
|
not_a_postcode => $not_a_postcode,
|
||||||
|
not_a_whole_postcode => $not_a_whole_postcode,
|
||||||
});
|
});
|
||||||
|
|
||||||
$validation->required('valid_email')->email;
|
$validation->required('valid_email')->email;
|
||||||
|
@ -29,8 +31,9 @@ $validation->required('invalid_email')->email;
|
||||||
$validation->required('valid_postcode')->postcode;
|
$validation->required('valid_postcode')->postcode;
|
||||||
$validation->required('invalid_postcode')->postcode;
|
$validation->required('invalid_postcode')->postcode;
|
||||||
$validation->required('not_a_postcode')->postcode;
|
$validation->required('not_a_postcode')->postcode;
|
||||||
|
$validation->required('not_a_whole_postcode')->postcode;
|
||||||
|
|
||||||
ok $validation->has_error, 'Have Errors';
|
ok $validation->has_error, 'Have Errors';
|
||||||
is_deeply $validation->failed, [ qw/ invalid_email invalid_postcode not_a_postcode / ], 'Correct Errors';
|
is_deeply $validation->failed, [ qw/ invalid_email invalid_postcode not_a_postcode not_a_whole_postcode / ], 'Correct Errors';
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
Reference in a new issue