Data-FormValidator - Data::FormValidator::Filters

Posted on Sat Mar 31 17:32:03 2007 by peterdd
Data::FormValidator::Filters

The Data::FormValidator::Filters needs some better regular expressions for filtering. Normally I don't use filters, because I'm very strict and if a validator constraint mismatch the whole data/form will be rejected. But there are too cases where it could be useful to accept portions of the submitted form data.

The current filters like pos_integer or neg_integer could be polished by modifying the regular expressions there.

Here is a perl oneliner approach for filtering the first positive integer in a given string:

perl -e 'my $v="sample-58-k689a-t+7646"; $res= ($v =~ qr/([0-9]+)/)[0]; print $res."\n";'

... should print 58.

Maybe this regexp can be simplified. The problem I see with this regexp is that negative integers get positive by this filter, so in this exaample: should it print 689 ?

Further there could be more contraints/filter types like latitude/longitude. For googlemaps data I use that constraints:

'lat' => qr/^[\+\-]?([0-9](\.[0-9]+)?|[0-8][0-9](\.[0-9]+)?|90|90\.(0)+)$/, 'lng' => qr/^[\+\-]?([0-9](\.[0-9]+)?|[0-9][0-9](\.[0-9]+)?|1[0-7][0-9](\.[0-9]+)?|180|180\.(0)+)$/ +,

Peter Liscovius

Write a response