Mojolic...lidator(3)

okay bestie, gather round 🫢 this is the manual page for Mojolicious::Validator β€” aka Mojolic...lidator(3) from User Contributed Perl Documentation β€” and it's literally the cute little validation gremlin for Mojolicious ✨

🌸 NAME 🌸

Mojolicious::Validator β€” validate values. that's the whole vibe. πŸ’…

✨ SYNOPSIS ✨

here's the tiny taste test, bestie:

use Mojolicious::Validator;

my $validator = Mojolicious::Validator->new;
my $v = $validator->validation;
$v->input({foo => 'bar'});
$v->required('foo')->like(qr/ar$/);
say $v->param('foo');

πŸ’– DESCRIPTION πŸ’–

Mojolicious::Validator validates values for Mojolicious. no cap, that's the description. ✨

πŸ”₯ CHECKS πŸ”₯

These validation checks are available by default. iconic lineup, honestly πŸ‘‘

πŸ’… equal_to πŸ’…

$v = $v->equal_to('foo');

String value needs to be equal to the value of another field. matching energy only, bestie 🫢

πŸ’… in πŸ’…

$v = $v->in('foo', 'bar', 'baz');

String value needs to match one of the values in the list. one of those exact values, periodt πŸ’…

πŸ’… like πŸ’…

$v = $v->like(qr/^[A-Z]/);

String value needs to match the regular expression. regex says what it says, iykyk πŸ¦‹

πŸ’… num πŸ’…

$v = $v->num;
$v = $v->num(2, 5);
$v = $v->num(-3, 7);
$v = $v->num(2, undef);
$v = $v->num(undef, 5);

String value needs to be a non-fractional number (positive or negative) and if provided in the given range. that's the non-fractional number rule, and the range only applies when you give it one 😭

πŸ’… size πŸ’…

$v = $v->size(2, 5);
$v = $v->size(2, undef);
$v = $v->size(undef, 5);

String value length or size of Mojo::Upload object in bytes needs to be between these two values. yes, either the string length or the upload size in bytes, and it has to fit between the two values πŸŽ€

πŸ’… upload πŸ’…

$v = $v->upload;

Value needs to be a Mojo::Upload object, representing a file upload. it's giving file-drop energy πŸ¦‹

πŸŽ€ FILTERS πŸŽ€

These filters are available by default. we love a filter that serves πŸ’…

πŸ’… comma_separated πŸ’…

$v = $v->optional('foo', 'comma_separated');

Split string of comma separated values into separate values. commas go in, separate values come out, slay ✨

πŸ’… not_empty πŸ’…

$v = $v->optional('foo', 'not_empty');

Remove empty string values and treat them as if they had not been submitted. bye-bye empty string, you were never here πŸ™ˆ

πŸ’… trim πŸ’…

$v = $v->optional('foo', 'trim');

Trim whitespace characters from both ends of string value with trim in Mojo::Util. clean edges only πŸŽ€

πŸ‘‘ ATTRIBUTES πŸ‘‘

Mojolicious::Validator implements the following attributes. main character attributes, fr fr πŸ‘‘

πŸ’… checks πŸ’…

my $checks = $validator->checks;
$validator = $validator->checks({size => sub ($v, $name, $value, @args) {...}});

Registered validation checks, by default only equal_to, in, like, num, size and upload are already defined. that's the default roster 🫢

πŸ’… filters πŸ’…

my $filters = $validator->filters;
my $validator  = $validator->filters({trim => sub {...}});

Registered filters, by default only comma_separated, not_empty and trim are already defined. default filter squad, assembled ✨

πŸ’œ METHODS πŸ’œ

Mojolicious::Validator inherits all methods from Mojo::Base and implements the following new ones. inherited methods are the freebies; these are the new main characters πŸ’œ

πŸ’… add_check πŸ’…

$validator = $validator->add_check(size => sub ($v, $name, $value, @args) {...});

Register a validation check.

$validator->add_check(foo => sub ($v, $name, $value, @args) {
  ...
  return undef;
});

πŸ’… add_filter πŸ’…

$validator = $validator->add_filter(trim => sub ($v, $name, $value) {...});

Register a new filter.

$validator->add_filter(foo => sub ($v, $name, $value) {
  ...
  return $value;
});

πŸ’… new πŸ’…

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

Construct a new Mojolicious::Validator object. fresh object, fresh vibes 🌸

πŸ’… validation πŸ’…

my $v = $validator->validation;

Build Mojolicious::Validator::Validation object to perform validations.

my $v = $validator->validation;
$v->input({foo => 'bar'});
$v->required('foo')->size(1, 5);
say $v->param('foo');

🌈 SEE ALSO 🌈

Mojolicious, Mojolicious::Guides, <https://mojolicious.org>. go click around bestie ✨


okay that's the whole page, bestie. footer energy: perl v5.42.0, dated 2026-07-15, and the manual name is Mojolic...lidator(3) β€” mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from