NAME
Mojolicious::Validator - Validate form data
SYNOPSIS
use Mojolicious::Validator;
my $validator = Mojolicious::Validator->new;
my $validation = $validator->validation;
$validation->input({foo => 'bar'});
$validation->required('foo')->like(qr/ar$/);
say $validation->param('foo');
DESCRIPTION
Mojolicious::Validator validates form data. Note that this module is EXPERIMENTAL and might change without warning!
CHECKS
These validation checks are available by default.
equal_to
$validation->equal_to('foo');
Value needs to be equal to the value of another field.
in
$validation->in(qw(foo bar baz));
Value needs to match one of the values in the list.
like
$validation->like(qr/^[A-Z]/);
Value needs to match the regular expression.
size
$validation->size(2, 5);
Value length in characters needs to be between these two values.
ATTRIBUTES
Mojolicious::Validator implements the following attributes.
checks
my $checks = $validator->checks;
$validator = $validator->checks({size => sub {...}});
Registered validation checks, by default only equal_to
, in
, like
and size
are already defined.
METHODS
Mojolicious::Validator inherits all methods from Mojo::Base and implements the following new ones.
add_check
$validator = $validator->add_check(size => sub {...});
Register a new validation check.
validation
my $validation = $validator->validation;
Build Mojolicious::Validator::Validation object to perform validations.
my $validation = $validator->validation;
$validation->input({foo => 'bar'});
$validation->required('foo')->size(1, 5);
say $validation->param('foo');