NAME
Mojolicious::Validator - Validate form data
SYNOPSIS
use Mojolicious::Validator;
my $validator = Mojolicious::Validator->new;
my $validation = $validator->validation;
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('foo', 'bar', 'baz');
Value needs to match one of the values in the list.
regex
$validation->regex(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
, regex
and size
are already defined.
errors
my $errors = $validator->errors;
$validator = $validator->errors({size => sub {...}});
Registered generators for dynamic error messages, by default only equal_to
, in
, required
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.
add_error
$validator = $validator->add_error(size => sub {...});
Register a new generator for dynamic error messages.
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');