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
- opensuse-leap 16.0: perl-Mojolicious 9.480.0-bp160.2.1 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms