1Data::FormValidator::FiUlsteerrsC(o3n)tributed Perl DocuDmaetnat:a:tFioornmValidator::Filters(3)
2
3
4

NAME

6       Data::FormValidator::Filters - Basic set of filters available in an
7       Data::FormValidator profile.
8

SYNOPSIS

10           use Data::FormValidator;
11
12           %profile = (
13               filters => 'trim',
14               ...
15           );
16
17           my $results = Data::FormValidator->check(  \%data, \%profile );
18

DESCRIPTION

20       These are the builtin filters which may be specified as a name in the
21       filters, field_filters, and field_filter_regexp_map parameters of the
22       input profile.
23
24       Filters are applied as the first step of validation, possibly modifying
25       a copy of the validation before any constraints are checked.
26
28       As a long time maintainer and user of Data::FormValidator, I recommend
29       that filters be used with caution. They are immediately modifying the
30       input provided, so the original data is lost. The few I recommend
31       include "trim", which removes leading and trailing whitespace. I have
32       this turned on by default by using
33       CGI::Application::Plugin::ValidateRM. It's also generally safe to use
34       the "lc" and "uc" filters if you need that kind of data transformation.
35
36       Beyond simple filters, I recommend transforming the "valid" hash
37       returned from validation if further changes are needed.
38

PROCEDURAL INTERFACE

40       You may also call these functions directly through the procedural
41       interface by either importing them directly or importing the whole
42       :filters group. For example, if you want to access the trim function
43       directly, you could either do:
44
45           use Data::FormValidator::Filters (qw/filter_trim/);
46           # or
47           use Data::FormValidator::Filters (qw/:filters/);
48
49           $string = filter_trim($string);
50
51       Notice that when you call filters directly, you'll need to prefix the
52       filter name with "filter_".
53

THE FILTERS

55   FV_split
56         use Data::FormValidator::Filters qw(FV_split);
57
58         # Validate every e-mail in a comma separated list
59
60         field_filters => {
61            several_emails  => FV_split(qr/\s*,\s*/),
62
63            # Any pattern that can be used by the 'split' builtin works.
64            tab_sep_field   => FV_split('\t'),
65         },
66         constraint_methods => {
67           several_emails => email(),
68         },
69
70       With this filter, you can split a field into multiple values. The
71       constraint for the field will then be applied to every value.
72
73       This filter has a different naming convention because it is a higher-
74       order function.  Rather than returning a value directly, it returns a
75       code reference to a standard Data::FormValidator filter.
76
77       After successfully being validated the values will appear as an
78       arrayref.
79
80   FV_replace
81         use Data::FormValidator::Filters qw(FV_replace);
82
83         field_filters => {
84            first_name   => FV_replace(qr/Mark/,'Don'),
85         },
86
87       FV_replace is a shorthand for writing simple find-and-replace filters.
88       The above filter would be translated to this:
89
90        sub { my $v = shift; $v =~ s/Mark/Don/; $v }
91
92       For more complex filters, just write your own.
93
94   trim
95       Remove white space at the front and end of the fields.
96
97   strip
98       Runs of white space are replaced by a single space.
99
100   digit
101       Remove non digits characters from the input.
102
103   alphanum
104       Remove non alphanumeric characters from the input.
105
106   integer
107       Extract from its input a valid integer number.
108
109   pos_integer
110       Extract from its input a valid positive integer number.
111
112       Bugs: This filter won't extract "9" from "a9+", it will instead extract
113       "9+"
114
115   neg_integer
116       Extract from its input a valid negative integer number.
117
118       Bugs: This filter will currently filter the case of "a9-" to become
119       "9-", which it should leave it alone.
120
121   decimal
122       Extract from its input a valid decimal number.
123
124       Bugs: Given "1,000.23", it will currently return "1.000.23"
125
126   pos_decimal
127       Extract from its input a valid positive decimal number.
128
129       Bugs: Given "1,000.23", it will currently return "1.000.23"
130
131   neg_decimal
132       Extract from its input a valid negative decimal number.
133
134       Bugs: Given "1,000.23", it will currently return "1.000.23"
135
136   dollars
137       Extract from its input a valid number to express dollars like currency.
138
139       Bugs: This filter won't currently remove trailing numbers like "1.234".
140
141   phone
142       Filters out characters which aren't valid for an phone number. (Only
143       accept digits [0-9], space, comma, minus, parenthesis, period and pound
144       [#].)
145
146   sql_wildcard
147       Transforms shell glob wildcard (*) to the SQL like wildcard (%).
148
149   quotemeta
150       Calls the quotemeta (quote non alphanumeric character) builtin on its
151       input.
152
153   lc
154       Calls the lc (convert to lowercase) builtin on its input.
155
156   uc
157       Calls the uc (convert to uppercase) builtin on its input.
158
159   ucfirst
160       Calls the ucfirst (Uppercase first letter) builtin on its input.
161

SEE ALSO

163       o
164            L<Data::FormValidator>
165
166       o
167            L<Data::FormValidator::Constraints>
168
169       o
170            L<Data::FormValidator::Filters::Image> - shrink incoming image uploads
171

AUTHOR

173        Author:  Francis J. Lacoste <francis.lacoste@iNsu.COM>
174        Maintainer: Mark Stosberg <mark@summersault.com>
175
177       Copyright (c) 1999,2000 iNsu Innovations Inc.  All rights reserved.
178
179       This program is free software; you can redistribute it and/or modify it
180       under the terms as perl itself.
181
182
183
184perl v5.32.0                      2020-07-28   Data::FormValidator::Filters(3)
Impressum