Validate::Tiny

Minimalistic data validation
Download

Validate::Tiny Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Publisher Name:
  • minimalist
  • Publisher web site:
  • http://search.cpan.org/~minimal/

Validate::Tiny Tags


Validate::Tiny Description

Minimalistic data validation 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.SYNOPSISFilter and validate user input from forms, etc. use Validate::Tiny qw/validate :util/; my $rules = { # List of fields to look for fields => , # Filters to run on all fields filters => =~ s/\W/./g; $_; }, ], # Checks to perform on all fields checks => => 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}; ... } ... Requirements: · Perl


Validate::Tiny Related Software