FU
view release on metacpan or search on metacpan
FU/Validate.pm view on Meta::CPAN
return either a false value or a hashref. The hashref will have the
I<validation> key set to I<func>, and this will be returned as error object.
When I<func> is used inside a custom validation, the returned error object will
have its I<validation> field set to the name of the custom validation. This
makes custom validations to behave as first-class validations in terms of error
reporting.
=back
=head1 Standard validations
Standard validations are provided by the module. It is possible to override,
re-implement and supplement these with custom validations. Internally, these
are, in fact, implemented as custom validations.
=over
=item regex => $re
Implies C<< type => 'scalar' >>. Validate the input against a regular
expression.
=item enum => $options
Implies C<< type => 'scalar' >>. Validate the input against a list of known
values. C<$options> can be either a scalar (in which case that is the only
permitted input), an array (listing all possible inputs) or a hash (where the
hash keys are considered to be the list of permitted inputs).
=item minlength => $num
Minimum length of the input. The I<length> is the string C<length()> if the
input is a scalar, the number of elements if the input is an array, or the
number of keys if the input is a hash.
=item maxlength => $num
Maximum length of the input.
=item length => $option
If C<$option> is a number, then this specifies the exact length of the input.
If C<$option> is an array, then this is a shorthand for
C<[$minlength,$maxlength]>.
=item anybool => 1
Accept any value of any type as input, and normalize it to either C<true> or
C<false> according to Perl's idea of truth.
=item bool => 1
Require the input to be a boolean type as per C<to_bool()> in L<FU::Util>.
=item num => 1
Implies C<< type => 'scalar' >>. Require the input to be a number formatted
using the format permitted by JSON. Note that this is slightly more restrictive
from Perl's number formatting, in that 'NaN', 'Inf' and thousand separators are
not permitted. The value is normalized to a Perl integer or floating point
value, which means precision for large numbers may be lost.
=item int => 1
Implies C<< type => 'scalar' >>. Require the input to be an (at most) 64-bit
integer.
=item uint => 1
Implies C<< type => 'scalar' >>. Require the input to be an (at most) 64-bit
unsigned integer.
=item min => $num
Implies C<< num => 1 >>. Require the input to be larger than or equal to
C<$num>.
=item max => $num
Implies C<< num => 1 >>. Require the input to be smaller than or equal to
C<$num>.
=item range => [$min,$max]
Equivalent to C<< min => $min, max => $max >>.
=item ascii => 1
Implies C<< type => 'scalar' >>. Require the input to wholly consist of
printable ASCII characters.
=item sl => 1
Implies C<< type => 'scalar' >>. Require the input to be a single line of text.
Useful for validating C<< <input type="text"> >> form elements, which really
should not result in multi-line input.
=item ipv4 => 1
Implies C<< type => 'scalar' >>. Require the input to be an IPv4 address.
=item ipv6 => 1
Implies C<< type => 'scalar' >>. Require the input to be an IPv6 address. Note
that the IP address is not normalized, and fancy features such as
IPv4-manned-IPv6 addresses are not permitted.
=item ip => 1
Require either C<< ipv4 => 1 >> or C<< ipv6 => 1 >>.
=item email => 1
Implies C<< type => 'scalar' >>. Validate the email address against a
monstrosity of a regular expression. This email validation is designed to catch
obviously invalid addresses and addresses that, while compliant with some RFCs,
will not be accepted by most actual SMTP implementations.
Email validation is quite a minefield, see L<Data::Validate::Email> for an
( run in 1.585 second using v1.01-cache-2.11-cpan-39bf76dae61 )