PerlOnTheWay has asked for the wisdom of the Perl Monks concerning the following question:

I only find how to validate it as 3 distinct fields:

... { date => ['year', 'month', 'day'] } => ['DATE'], ...

But now I want to validate them as a whole(stored in a single <input type="text" name="date" />) in the format xxxx-xx-xx, how to do that?

Replies are listed 'Best First'.
Re: How do I validate DATE as a single field with FormValidator::Simple?
by Anonymous Monk on Aug 12, 2011 at 06:36 UTC

    I only find how to validate it as 3 distinct fields:

    Then you stopped reading the documentation before you found the answer to your question

    datetime => [ [ 'DATETIME_STRPTIME', '%Y-%m-%dT%T%z' ] ], datetime => [ [qw/DATETIME_FORMAT MySQL/] ],

    Making an intuitive leap, I guess that this might also work

    perl -MFormValidator::Simple -MCGI -le " my $q = CGI->new({qw/ snot 20 +11-08-11 /}); my $result = FormValidator::Simple->check( $q => [ { no +se => [qw/ snot /] } => [ q/DATE/ ], ] ); warn $result->has_error; "
    update: after testing, it doesn't :) oh well,
    perl -MFormValidator::Simple -MCGI -le " my $q = CGI->new({qw/ snot 2 +011-08-11 /}); my $result = FormValidator::Simple->check( $q => [ sno +t => [ [ qw/ DATETIME_STRPTIME %Y-%m-%d / ] ], ] ); warn $result->has +_error; "