perldoc > Data::FormValidator::Filters

๐Ÿ“› NAME

Data::FormValidator::Filters โ€” Basic set of filters available in an Data::FormValidator profile.

๐Ÿš€ Quick Reference

Use CaseCommandDescription
๐Ÿงน Remove leading/trailing whitespacefilters => 'trim'Trim whitespace from all fields
โœ‚๏ธ Split field into multiple valuesFV_split(qr/\s*,\s*/)Split field by pattern, validate each value individually
๐Ÿ” Find and replace in fieldFV_replace(qr/Mark/,'Don')Simple regex find-and-replace filter
๐Ÿ”ค Convert to lowercasefilters => 'lc'Lowercase all input
๐Ÿ”  Convert to uppercasefilters => 'uc'Uppercase all input
๐Ÿ”ข Keep only digitsfilters => 'digit'Remove non-digit characters
๐Ÿ”ค Keep only alphanumericfilters => 'alphanum'Remove non-alphanumeric characters
๐Ÿ”ข Extract integerfilters => 'integer'Extract a valid integer number
๐Ÿ’ฐ Extract currency amountfilters => 'dollars'Extract valid dollar amount
๐Ÿ“ž Clean phone numberfilters => 'phone'Keep only valid phone characters
๐Ÿ—„๏ธ Convert shell glob to SQL LIKEfilters => 'sql_wildcard'Transform * to % for SQL wildcards
๐Ÿ“ Quote metacharactersfilters => 'quotemeta'Escape all non-alphanumeric characters

๐Ÿ“‹ SYNOPSIS

use Data::FormValidator;

%profile = (
    filters => 'trim',
    ...
);

my $results = Data::FormValidator->check(  \%data, \%profile );

๐Ÿ“– DESCRIPTION

These are the builtin filters which may be specified as a name in the filters, field_filters, and field_filter_regexp_map parameters of the input profile.

Filters are applied as the first step of validation, possibly modifying a copy of the validation before any constraints are checked.

๐Ÿ’ก RECOMMENDED USE

As a long time maintainer and user of Data::FormValidator, I recommend that filters be used with caution. They are immediately modifying the input provided, so the original data is lost. The few I recommend include trim, which removes leading and trailing whitespace. I have this turned on by default by using CGI::Application::Plugin::ValidateRM. It's also generally safe to use the lc and uc filters if you need that kind of data transformation.

Beyond simple filters, I recommend transforming the valid hash returned from validation if further changes are needed.

๐Ÿ”ง PROCEDURAL INTERFACE

You may also call these functions directly through the procedural interface by either importing them directly or importing the whole :filters group. For example, if you want to access the trim function directly, you could either do:

use Data::FormValidator::Filters (qw/filter_trim/);
# or
use Data::FormValidator::Filters (qw/:filters/);

$string = filter_trim($string);

Notice that when you call filters directly, you'll need to prefix the filter name with filter_.

๐ŸŽ›๏ธ 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 will then be applied to every value.

This filter has a different naming convention because it is a higher-order function. Rather than returning a value directly, it returns a code reference to a standard Data::FormValidator filter.

After successfully being 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 above filter would be translated to this:

sub { my $v = shift; $v =~ s/Mark/Don/; $v }

For more complex filters, just write your own.

๐Ÿงน 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 extract "9" from "a9+", it will instead extract "9+"

โž– neg_integer

Extract from its input a valid negative integer number.

โš ๏ธ Bugs: This filter will currently filter the case of "a9-" to become "9-", which it should leave it alone.

๐Ÿ”ข decimal

Extract from its input a valid decimal number.

โš ๏ธ Bugs: Given "1,000.23", it will currently return "1.000.23"

โž• pos_decimal

Extract from its input a valid positive decimal number.

โš ๏ธ Bugs: Given "1,000.23", it will currently return "1.000.23"

โž– neg_decimal

Extract from its input a valid negative decimal number.

โš ๏ธ Bugs: Given "1,000.23", it will currently return "1.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 a 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

๐Ÿ‘ค AUTHOR

Author: Francis J. Lacoste <francis.lacoste AT iNsu.COM>
Maintainer: Mark Stosberg <mark AT 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.

Data::FormValidator::Filters
๐Ÿ“› NAME ๐Ÿš€ Quick Reference ๐Ÿ“‹ SYNOPSIS ๐Ÿ“– DESCRIPTION ๐Ÿ’ก RECOMMENDED USE ๐Ÿ”ง PROCEDURAL INTERFACE ๐ŸŽ›๏ธ THE FILTERS
โœ‚๏ธ FV_split ๐Ÿ” FV_replace ๐Ÿงน trim โœจ strip ๐Ÿ”ข digit ๐Ÿ”ค alphanum ๐Ÿ”ข integer โž• pos_integer โž– neg_integer ๐Ÿ”ข decimal โž• pos_decimal โž– neg_decimal ๐Ÿ’ฐ dollars ๐Ÿ“ž phone ๐Ÿ—„๏ธ sql_wildcard ๐Ÿ“ quotemeta ๐Ÿ”ก lc ๐Ÿ”  uc ๐Ÿ”ค ucfirst
๐Ÿ“š SEE ALSO ๐Ÿ‘ค AUTHOR ยฉ๏ธ COPYRIGHT

Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-27 08:06 @216.73.216.194
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format

^_top_^