NAME
Mojolicious::Plugin::AdditionalValidationChecks
VERSION
version 0.06
SYNOPSIS
# Mojolicious
$self->plugin('AdditionalValidationChecks');
# Controller
my $validation = $self->validation;
$validation->input({ nr => 3 });
$validation->required( 'nr' )->max( 10 );
DESCRIPTION
Mojolicious::Plugin::AdditionalValidationChecks adds a few validation checks to the Mojolicious validator.
NAME
Mojolicious::Plugin::AdditionalValidationChecks - Mojolicious Plugin
CHECKS
These checks are added:
Checks that the given value is a valid email. It uses Email::Valid
.
simple check
This does only check whether the given mailaddress is valid or not
my $validation = $self->validation;
$validation->input({ email_address => 'dummy@test.example' });
$validation->required( 'email_address' )->email();
check also MX
Check if there's a mail host for it
my $validation = $self->validation;
$validation->input({ email_address => 'dummy@test.example' });
$validation->required( 'email_address' )->email(-mxcheck => 1);
phone
Checks if the given value is a phone number:
my $validation = $self->validation;
$validation->input({ nr => '+49 123 / 1321352' });
$validation->required( 'nr' )->phone(); # valid
$validation->input({ nr => '00 123 / 1321352' });
$validation->required( 'nr' )->phone(); # valid
$validation->input({ nr => '0123 / 1321352' });
$validation->required( 'nr' )->phone(); # valid
min
Checks a number for a minimum value. If a non-number is passed, it's always invalid
my $validation = $self->validation;
$validation->input({ nr => 3 });
$validation->required( 'nr' )->min( 10 ); # not valid
$validation->required( 'nr' )->min( 2 ); # valid
$validation->input({ nr => 'abc' });
$validation->required( 'nr' )->min( 10 ); # not valid
max
Checks a number for a maximum value. If a non-number is passed, it's always invalid
my $validation = $self->validation;
$validation->input({ nr => 3 });
$validation->required( 'nr' )->max( 10 ); # not valid
$validation->required( 'nr' )->max( 2 ); # valid
$validation->input({ nr => 'abc' });
$validation->required( 'nr' )->max( 10 ); # not valid
length
In contrast to the size
"built-in", this check also allows to omit the maximum length.
my $validation = $self->validation;
$validation->input({ word => 'abcde' });
$validation->required( 'word' )->length( 2, 5 ); # valid
$validation->required( 'word' )->length( 2 ); # valid
$validation->required( 'word' )->length( 8, 10 ); # not valid
int
Checks if a number is an integer. If a non-number is passed, it's always invalid
my $validation = $self->validation;
$validation->input({ nr => 3 });
$validation->required( 'nr' )->int(); # valid
$validation->input({ nr => 'abc' });
$validation->required( 'nr' )->int(); # not valid
$validation->input({ nr => '3.0' });
$validation->required( 'nr' )->int(); # not valid
http_url
Checks if a given string is an absolute URL with http or https scheme.
my $validation = $self->validation;
$validation->input({ url => 'http://perl-services.de' });
$validation->required( 'url' )->http_url(); # valid
$validation->input({ url => 'https://metacpan.org' });
$validation->required( 'url' )->http_url(); # valid
$validation->input({ url => 3 });
$validation->required( 'url' )->http_url(); # not valid
$validation->input({ url => 'mailto:dummy@example.com' });
$validation->required( 'url' )->http_url(); # not valid
not
The opposite of in
.
my $validation = $self->validation;
$validation->input({ id => '3' });
$validation->required( 'id' )->not( 2, 5 ); # valid
$validation->required( 'id' )->not( 2 ); # valid
$validation->required( 'id' )->not( 3, 8, 10 ); # not valid
$validation->required( 'id' )->not( 3 ); # not valid
color
Checks if the given value is a "color". There are three flavours of colors:
rgb
my $validation = $self->validation; $validation->input({ color => 'rgb(11,22,33)' }); $validation->required( 'color' )->color( 'rgb' ); # valid $validation->input({ color => 'rgb(11, 22, 33)' }); $validation->required( 'color' )->color( 'rgb' ); # valid $validation->input({ color => 'rgb(11%,22%,33%)' }); $validation->required( 'color' )->color( 'rgb' ); # valid $validation->input({ color => 'rgb(11%, 22%, 33%)' }); $validation->required( 'color' )->color( 'rgb' ); # valid
rgba
my $validation = $self->validation; $validation->input({ color => 'rgba(11,22,33,0)' }); $validation->required( 'color' )->color( 'rgba' ); # valid $validation->input({ color => 'rgb(11, 22, 33,0.0)' }); $validation->required( 'color' )->color( 'rgba' ); # valid $validation->input({ color => 'rgb(11, 22, 33,0.6)' }); $validation->required( 'color' )->color( 'rgba' ); # valid $validation->input({ color => 'rgb(11%,22%,33%, 1)' }); $validation->required( 'color' )->color( 'rgba' ); # valid $validation->input({ color => 'rgb(11%, 22%, 33%, 1.0)' }); $validation->required( 'color' )->color( 'rgba' ); # valid
hex
my $validation = $self->validation; $validation->input({ color => '#afe' }); $validation->required( 'color' )->color( 'hex' ); # valid $validation->input({ color => '#affe12' }); $validation->required( 'color' )->color( 'hex' ); # valid
MORE COMMON CHECKS?
If you know some commonly used checks, please add an issue at https://github.com/reneeb/Mojolicious-Plugin-AdditionalValidationChecks/issues.
SEE ALSO
Mojolicious, Mojolicious::Guides, http://mojolicio.us.
AUTHOR
Renee Baecker <reneeb@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2014 by Renee Baecker.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)