GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Data::FormValidator::Filters(3) User Contributed Perl Documentation Data::FormValidator::Filters(3)

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

    use Data::FormValidator;

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

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

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.

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.

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_".

  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.

  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.

Remove white space at the front and end of the fields.

Runs of white space are replaced by a single space.

Remove non digits characters from the input.

Remove non alphanumeric characters from the input.

Extract from its input a valid integer number.

Extract from its input a valid positive integer number.

Bugs: This filter won't extract "9" from "a9+", it will instead extract "9+"

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.

Extract from its input a valid decimal number.

Bugs: Given "1,000.23", it will currently return "1.000.23"

Extract from its input a valid positive decimal number.

Bugs: Given "1,000.23", it will currently return "1.000.23"

Extract from its input a valid negative decimal number.

Bugs: Given "1,000.23", it will currently return "1.000.23"

Extract from its input a valid number to express dollars like currency.

Bugs: This filter won't currently remove trailing numbers like "1.234".

Filters out characters which aren't valid for an phone number. (Only accept digits [0-9], space, comma, minus, parenthesis, period and pound [#].)

Transforms shell glob wildcard (*) to the SQL like wildcard (%).

Calls the quotemeta (quote non alphanumeric character) builtin on its input.

Calls the lc (convert to lowercase) builtin on its input.

Calls the uc (convert to uppercase) builtin on its input.

Calls the ucfirst (Uppercase first letter) builtin on its input.

o
 L<Data::FormValidator>
    
o
 L<Data::FormValidator::Constraints>
    
o
 L<Data::FormValidator::Filters::Image> - shrink incoming image uploads
    

 Author:  Francis J. Lacoste <francis.lacoste@iNsu.COM>
 Maintainer: Mark Stosberg <mark@summersault.com>

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.

2017-08-28 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.