my $profile = { required => [qw( cc_type cc_name cc_number cc_expiry cc_3digit_code )], constraints => { # field must match one of visa amex or mc cc_type => qr/^(visa|amex|mc)$/, # match to a name cc_name => qr/^([\w ]+)$/, # use built in cc_number function to validate # credit card numbers. the validation # routine needs both the cc_number and the # cc_type to do the validation cc_number => { constraint => 'cc_number', params => [qw(cc_number cc_type)] }, # use the builting cc_exp routine to validate # the expiry date cc_expiry => 'cc_exp', # field must be a 3 or 4 word or # digit characters cc_3digit_code => qr/^([\w\d]{3,4})$/, }, }; # Check the profile to make sure everything was filled in correctly my $query = CGI->new(); my $results = Data::FormValidator->check($query, $profile); if ($results->has_invalid or $results->has_missing) { # There were some problems with the form values # so redisplay the form ... } else { # The form was properly filled out my $valid = $results->valid(); # now $valid contains a hashref of all the validated data # so do something with the values ... }