Data::...ilters(3pm)
π NAME π
Data::FormValidator::Filters β a whole basic lil set of filters you get handed in a Data::FormValidator profile. No cap, they come free with the package. π«Ά
β¨ SYNOPSIS β¨
use Data::FormValidator;
%profile = (
filters => 'trim',
...
);
my $results = Data::FormValidator->check( \%data, \%profile );
πΈ DESCRIPTION πΈ
Okay so these are the builtin filters, bestie. You can call them by name inside the filters, field_filters, and field_filter_regexp_map parameters of your input profile. iykyk.
Filters run as the very first step of validation, and they might be out here modifying a copy of the validation data before any constraints get checked. So they get first dibs. π
π RECOMMENDED USE π
Okay real talk, coming from someone who has been maintaining and using Data::FormValidator for a long time: use filters with caution, bestie. π They immediately modify the input you gave them, so the original data is gone. Poof. Not coming back.
The few I actually recommend:
trimβ it removes leading and trailing whitespace. I have this turned on by default viaCGI::Application::Plugin::ValidateRM. π§lcanducβ also generally safe if you need that kind of data transformation.
Beyond simple filters, my recommendation is: transform the valid hash that validation gives you back, if you need further changes. That's the move. π
π¦ PROCEDURAL INTERFACE π¦
You can also call these functions directly through the procedural interface β either import them directly or import the whole :filters group. For example, if you want to access the trim function directly, you could do either of these:
use Data::FormValidator::Filters (qw/filter_trim/);
# or
use Data::FormValidator::Filters (qw/:filters/);
$string = filter_trim($string);
Heads up: when you call filters directly, you'll need to prefix the filter name with filter_. That's just the vibe. Periodt.
π₯ THE FILTERS π₯
β FV_split β
use Data::FormValidator::Filters qw(FV_split);
# Validate every e-mail in a comma separated list
field_filters => {
several_emails => FV_split(qr/\s*,\s*/),
# Any pattern that can be used by the 'split' builtin works.
tab_sep_field => FV_split('\t'),
},
constraint_methods => {
several_emails => email(),
},
With this filter you can split a field into multiple values. The constraint for the field then gets applied to every value. Slay.
This one has a different naming convention because it's a higher-order function. Instead of returning a value directly, it returns a code reference to a standard Data::FormValidator filter. Fancy, right? π
After it's successfully validated, the values will appear as an arrayref.
π FV_replace π
use Data::FormValidator::Filters qw(FV_replace);
field_filters => {
first_name => FV_replace(qr/Mark/,'Don'),
},
FV_replace is a shorthand for writing simple find-and-replace filters. The filter above would be translated to this:
sub { my $v = shift; $v =~ s/Mark/Don/; $v }
For more complex filters, just write your own. You got this. πͺ
π trim π
Remove white space at the front and end of the fields.
π strip π
Runs of white space are replaced by a single space.
π digit π
Remove non digits characters from the input.
π alphanum π
Remove non alphanumeric characters from the input.
π integer π
Extract from its input a valid integer number.
π pos_integer π
Extract from its input a valid positive integer number.
Bugs: This filter won't extract9froma9+, it will instead extract9+π
π neg_integer π
Extract from its input a valid negative integer number.
Bugs: This filter will currently filter the case ofa9-to become9-, which it should leave it alone. π
π decimal π
Extract from its input a valid decimal number.
Bugs: Given1,000.23, it will currently return1.000.23π
π pos_decimal π
Extract from its input a valid positive decimal number.
Bugs: Given1,000.23, it will currently return1.000.23π
π neg_decimal π
Extract from its input a valid negative decimal number.
Bugs: Given1,000.23, it will currently return1.000.23π
π dollars π
Extract from its input a valid number to express dollars like currency.
Bugs: This filter won't currently remove trailing numbers like 1.234. π
π phone π
Filters out characters which aren't valid for an phone number. (Only accept digits [0-9], space, comma, minus, parenthesis, period and pound [#].)
π sql_wildcard π
Transforms shell glob wildcard (*) to the SQL like wildcard (%).
π quotemeta π
Calls the quotemeta (quote non alphanumeric character) builtin on its input.
π lc π
Calls the lc (convert to lowercase) builtin on its input.
π uc π
Calls the uc (convert to uppercase) builtin on its input.
π ucfirst π
Calls the ucfirst (Uppercase first letter) builtin on its input.
π SEE ALSO π
Data::FormValidatorData::FormValidator::ConstraintsData::FormValidator::Filters::Imageβ shrink incoming image uploads
π AUTHOR π
Author: Francis J. Lacoste <francis.lacoste@iNsu.COM>
Maintainer: Mark Stosberg <mark@summersault.com>
πΈ COPYRIGHT πΈ
Copyright (c) 1999,2000 iNsu Innovations Inc. All rights reserved.
This program is free software; you can redistribute it and/or modify it under the terms as perl itself.
And that's the whole page, bestie! π«Ά This lil beauty is perl v5.34.0, dated 2022-06-12, and it lives its life as Data::...ilters(3pm). Go forth and filter responsibly. π
β¨π
π¦ where this page comes from
- debian bookworm: libdata-formvalidator-perl 4.88-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libdata-formvalidator-perl 4.88-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libdata-formvalidator-perl 4.88-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libdata-formvalidator-perl 4.88-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libdata-formvalidator-perl 4.88-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms