Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Just another Perl shrine
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Maybe I am cognitively challenged, but I thought I did what the documentation says to do if there are multiple constraints to apply to a given field. To be clear, here is what the documentation says (a direct quote, but I don't see anything in the interface for editing this that lets me distinguish between such a quote and what I write)

MULTIPLE CONSTRAINTS

Multiple constraints can be applied to a single field by defining the value of the constraint to be an array reference. Each of the values in this array can be any of the constraint types defined above.

When using multiple constraints it is important to return the name of the constraint that failed so you can distinguish between them. To do that, either use a named constraint, or use the hash ref method of defining a constraint and include a name key with a value set to the name of your constraint. Here's an example:

my_zipcode_field => [ 'zip', { constraint => '/^406/', name => 'starts_with_406', } ],

You can use an array reference with a single constraint in it if you just want to have the name of your failed constraint returned in the above fashion. Read about the validate() function above to see how multiple constraints are returned differently with that method.

Now here is what I tried:

ccexpiry => [ 'ccexp', { constraint => sub { my ($dfv,$val) = @_; return $val =~ m/^\d{4}$/, }, name => 'must be_4_digits' }, { constraint => after_today('%m%y'), name => 'card_expired' } ],

Of course, this is part of a large profile hash that, prior to my attempt to use multiple constraints, was working fine. Now, here is the error I get:

[Thu Jan 31 15:58:27 2013] [error] [client 127.0.0.1] Value for constraint_method 'ccexp' not a code reference or Regexp . Do you need func(), not 'func'? at C:/Perl64/site/lib/Data/FormValidator.pm line 974., referer: http://localhost:9080/test.dfv.html

I am using the following packages.

use Business::CreditCard; use Business::CCCheck; use Data::FormValidator; use Data::FormValidator::Constraints qw(:closures); use Data::FormValidator::Constraints::DateTime qw(:all);

If there are others that you believe would be useful, I'd appreciate hearing about them, but as far as I can see, the ones I am using are pretty much sufficient for what I need right now.

Any insight on how I can fix these constraints would be appreciated.

Thanks

Ted


In reply to Problems with not so trivial data validation using Data::FormValidator by ted.byers

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others wandering the Monastery: (5)
    As of 2014-04-21 04:44 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (490 votes), past polls