Validate::Tiny is a Perl module that provides a simple, light and minimalistic way of validating user input. Except perl core modules and some test modules it has no other dependencies, which is why it does not implement any complicated checks and filters such as email and credit card matching. The basic idea of this module is to provide the validation functionality, and leave it up to the user to write their own data filters and checks. If you need a complete data validation solution that comes with many ready features, I recommend you to take a look at Data::FormValidator. If your validation logic is not too complicated or your form is relatively short, this module is a decent candidate for your project.
SYNOPSIS
Filter and validate user input from forms, etc.
use Validate::Tiny qw/validate :util/;
my $rules = {
# List of fields to look for
fields => [qw/name email pass pass2 gender/],
# Filters to run on all fields
filters => [
# Remove spaces from all
qr/.+/ => filter(qw/trim strip/),
# Lowercase email
email => filter('lc'),
# Remove non-alphanumeric symbols from
# both passwords
qr/pass?/ => sub {
$_[0] =~ s/\W/./g;
$_[0];
},
],
# Checks to perform on all fields
checks => [
# All of these are required
[qw/name email pass pass2/] => is_required(),
# pass2 must be equal to pass
pass2 => is_equal('pass'),
# custom sub validates an email address
email => sub {
my ( $param, $value ) = @_;
Email::Valid->address($value) ? undef : 'Invalid email';
},
# custom sub to validate gender
gender => sub {
my ( $param, $value ) = @_;
return $value eq 'M'
|| $value eq 'F' ? undef : 'Invalid gender';
}
]
};
# Validate the input agains the rules
my $result = validate( $input, $rules );
if ( $result->{success} ) {
my $values_hash = $result->{data};
...
}
else {
my $errors_hash = $result->{error};
...
}
...
Product's homepage
Requirements:
· Perl