GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  INPUT::VALIDATOR (3)

.ds Aq ’

NAME

Input::Validator - Input Validator

CONTENTS

SYNOPSIS



    my $validator = Input::Validator->new;

    # Fields
    $validator->field(phone)->required(1)->regexp(qr/^\d+$/);
    $validator->field([qw/firstname lastname/])
      ->each(sub { shift->required(1)->length(3, 20) });

    # Groups
    $validator->field([qw/password confirm_password/])
      ->each(sub { shift->required(1) });
    $validator->group(passwords => [qw/password confirm_password/])->equal;

    # Conditions
    $validator->field(document);
    $validator->field(number);
    $validator->when(document)->regexp(qr/^1$/)
      ->then(sub { shift->field(number)->required(1) });

    $validator->validate($values_hashref);
    my $errors_hashref = $validator->errors;
    my $pass_error = $validator->group(passwords)->error;
    my $validated_values_hashref = $validator->values;



DESCRIPTION

Data validator. Validates only the data. <B>NOB> form generation, <B>NOB> javascript generation, <B>NOB> other stuff that does something else. Only data validation!

FEATURES



    Validates data that is presented as a hash reference

    Multiple values

    Field registration

    Group validation

    Conditional validation



CONVENTIONS



    A value is considered empty when its value is C<undef>, C<> or
    contains only spaces.

    If a value is not required and during validation is empty there is B<NO>
    error.

    If explicit is set to true, then all values not explicitly required
    generate an error.

    If a value is passed as an array reference and an appropriate field is
    not multiple, than only the first value is taken, otherwise every value of
    the array reference is checked.



ATTRIBUTES

CWexplicit

Causes errors to be generated when unknown parameters exist.

CWhas_unknown_params

Unknown parameters exist in validated parameter hashref.

CWmessages



    my $validator =
      Input::Validator->new(
        messages => {REQUIRED => This field is required});



Replace default messages.

CWtrim

Trim field values. <B>ONB> by default.

METHODS

CWnew



    my $validator = Input::Validator->new;



Create a new Input::Validator object.

CWclear_errors



    $validator->clear_errors;



Clear errors.

CWfield



    $validator->field(foo);               # Input::Validator::Field object is returned
    $validator->field(foo);               # Already created field object is returned

    $validator->field(qw/foo bar baz/);     # Input::Validator::Bulk object is returned
    $validator->field([qw/foo bar baz/]);   # Input::Validator::Bulk object is returned



When a single value is passed create Input::Validator::Field object or return an already created field object.

When an array or an array reference is passed return Input::Validator::Bulk object. You can call each method to apply setting to multiple fields.



    $validator->field(qw/foo bar baz/)->each(sub { shift->required(1) });



CWgroup



    $validator->field(qw/foo bar/)->each(sub { shift->required(1) });
    $validator->group(all_or_none => [qw/foo bar/])->equal;



Register a group constraint that will be called on group of fields. If group validation fails the errors hashref will have the <B>groupB> name with an appropriate error message, <B>NOTB> fields’ names.

CWwhen



    $validator->field(document);
    $validator->field(number);
    $validator->when(document)->regexp(qr/^1$/)
      ->then(sub { shift->field(number)->required(1) });



Register a condition that is called when some conditions are met. You can do whatever you want in condition’s callback. Validation will be remade.

CWvalidate



    $validator->validate({a => b});
    $validator->validate({a => [b, c]});
    $validator->validate({a => [b, c], b => d});



Accept and validate a hash reference that represents data that is being validated. Input values can be either a SCALAR value or an ARRAREF value, which means that a field has multiple values. In case of an array reference, it is checked if a field can have multiple values. Otherwise only the first value is accepted and returned when values method is called.

CWerror



    $validator->error(foo => bar);



Set a custom error.

CWerrors



    $validator->errors; # {a => Required}



Return a hash reference of errors.

CWhas_errors



    $validator->has_errors;



Check if there are any errors.

CWvalues



    $validator->values;



Return a hash reference of validated values. Only registered fields are returned, that means that if some other values were passed to the validate method they are ignored.

CWall_values



    $validator->all_values;



Return a hash reference of all values. Only registered fields are returned. Useful for displaying wrong values for user to reenter.

DEVELOPMENT

    Repository



    http://github.com/vti/input-validator



AUTHOR

Viacheslav Tykhanovskyi, vti@cpan.org.

CREDITS

In alphabetical order:

Alex Voronov

Anatoliy Lapitskiy

Glen Hinkle

Marcus Ramberg

Naoya Ito

Yaroslav Korshak

COPYRIGHT AND LICENSE

Copyright (C) 2011, Viacheslav Tykhanovskyi.

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 INPUT::VALIDATOR (3) 2011-10-27

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.