Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.3 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67a
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Perl Modules

    Validate::Tiny 0.983

    Download button

    No screenshots available
    Downloads: 180  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    minimalist | More programs
    Perl Artistic License / FREE
    September 22nd, 2012, 08:06 GMT
    ROOT / Programming / Perl Modules

     Read user reviews (0)  Refer to a friend  Subscribe

    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.

    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

      


    TAGS:

    data validation | Perl module | Perl | data | validation

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM