Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Contact Us
Online Help
Domain Status
Man Pages

Virtual Servers

Topology Map

Server Agreement
Year 2038

USA Flag



Man Pages
Mojolicious::Validator(3) User Contributed Perl Documentation Mojolicious::Validator(3)

Mojolicious::Validator - Validate values

  use Mojolicious::Validator;
  my $validator = Mojolicious::Validator->new;
  my $v = $validator->validation;
  $v->input({foo => 'bar'});
  say $v->param('foo');

Mojolicious::Validator validates values for Mojolicious.

These validation checks are available by default.

  $v = $v->equal_to('foo');
String value needs to be equal to the value of another field.

  $v = $v->in('foo', 'bar', 'baz');
String value needs to match one of the values in the list.

  $v = $v->like(qr/^[A-Z]/);
String value needs to match the regular expression.

  $v = $v->num;
  $v = $v->num(2, 5);
  $v = $v->num(2, undef);
  $v = $v->num(undef, 5);
String value needs to be a non-fractional number and if provided in the given range.

  $v = $v->size(2, 5);
String value length or size of Mojo::Upload object in bytes needs to be between these two values.

  $v = $v->upload;
Value needs to be a Mojo::Upload object, representing a file upload.

These filters are available by default.

  $v = $v->optional('foo', 'trim');
Trim whitespace characters from both ends of string value with "trim" in Mojo::Util.

Mojolicious::Validator implements the following attributes.

  my $checks = $validator->checks;
  $validator = $validator->checks({size => sub {...}});
Registered validation checks, by default only "equal_to", "in", "like", "num", "size" and "upload" are already defined.

Mojolicious::Validator inherits all methods from Mojo::Base and implements the following new ones.

  $validator = $validator->add_check(size => sub {...});
Register a validation check.
  $validator->add_check(foo => sub {
    my ($v, $name, $value, @args) = @_;
    return undef;

  $validator = $validator->add_filter(trim => sub {...});
Register a new filter.
  $validator->add_filter(foo => sub {
    my ($v, $name, $value) = @_;
    return $value;

  my $validator = Mojolicious::Validator->new;
Construct a new Mojolicious::Validator object.

  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');

Mojolicious, Mojolicious::Guides, <>.
2018-11-22 perl v5.28.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.