Input::Validator::Field - Field object
$validator->field('foo'); $validator->field(qw/foo bar/); $validator->field([qw/foo bar baz/]);
Field object. Used internally.
messages
Error messages.
deflate
$field->deflate(sub { s/foo/bar/ });
Use this when you want to change value of field after validation.
error
$field->error('Invalid input'); my $error = $field->error;
Field error.
each
$field->each(sub { shift->required(1) });
Each method as described in Input::Validator::Bulk. Added here for convenience.
inflate
$field->inflate(sub { s/foo/bar/ });
Use this when you want to change value of field before validation.
multiple
$field->multiple(1);
Field can have multiple values. Use this when you want to allow array reference as a value.
$field->multiple(2, 5);
If you want to control how many multiple values there can be set min and max values.
min
max
$field->multiple(10);
When max value is omitted and is not 1 (because it doesn't make sense), number of values must be equal to this value.
1
name
$field->name('foo'); my $name = $field->name;
Field's name.
required
$field->required(1);
Whether field is required or not. See Input::Validator documentation what is an empty field.
trim
$field->trim(1);
Whether field's value should be trimmed before validation. It is ON by default.
callback
Shortcut
$field->constraint(callback => sub { ... });
clear_error
$field->clear_value;
Clears field's error.
clear_value
Clears field's value.
constraint
$field->constraint(length => [1, 2]);
Adds a new field's constraint.
is_defined
my $defined = $field->is_defined;
Checks whether field's value is defined.
is_empty
my $empty = $field->is_empty;
Checks whether field's value is empty.
is_valid
Checks whether all field's constraints are valid.
message
Holds error message.
value
my $value = $field->value; $field->value('foo')
Set or get field's value.
Input::Validator, Input::Validator::Constraint.
To install Input::Validator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Input::Validator
CPAN shell
perl -MCPAN -e shell install Input::Validator
For more information on module installation, please visit the detailed CPAN module installation guide.