Validate-Tiny
view release on metacpan or search on metacpan
t/filters/04-custom.t view on Meta::CPAN
use strict;
use warnings;
use Validate::Tiny ':all';
use Test::More;
$Validate::Tiny::FILTERS{only_digits} = sub {
my $val = shift;
return unless defined $val;
$val =~ s/\D//g;
return $val;
};
my $rules = {
fields => ['a'],
filters => [ a => filter('trim', 'only_digits') ]
};
my $res = validate({a => undef}, $rules);
is $res->{a}, undef;
$res = validate({ a => " abc123 " }, $rules);
is $res->{data}->{a}, '123';
done_testing;
( run in 0.877 second using v1.01-cache-2.11-cpan-140bd7fdf52 )