in reply to Quick Regex Question

It's hard to say without the values you're testing against. Maybe there is whitespace at the beginning or end of your values or something else.

Replies are listed 'Best First'.
Re^2: Quick Regex Question
by Trihedralguy (Pilgrim) on May 07, 2007 at 20:17 UTC
    My values are just like 03/30/2007 something like that or just DD/MM/YYYY ??? The input is done by me or the user so there is no whitespace.

      A better post would have been then:

      $dated = '03/30/2007'; if ($dated =~ m/^[0-3][0-9]\/[0-1][0-9]\/[1-2][0-9][0-9][0-9]$/) { } else { #User entered an invaild date. $passfail = 0; $errmsg = 'Unable to use date format. Please use "MM/DD/YYYY" or MM-DD +-YYYY for the Date Delivered Field'; $errtitle = 'Validation Error'; $seconds = 7; }

      This fails, because your second segment does only allow for 00 to 19 and never for 30, which seems sensible if you want to validate dates in the format DD/MM/YYYY as you say. Your error message doesn't match that, as there you claim to match MM/DD/YYYY...

      Well.. that is easy... your dates are DD/MM/YYYY bust your regexp is MM/DD/YYYY first section matches 00 to 19, second matches 00 to 39, so many values you pass would fail...
      /^(?:[0-3]\d\/[01]\d\/(?:19|20)\d\d)?$/
      will do it, but as other people have said, there are better ways.

                      - Ant
                      - Some of my best work - (1 2 3)

        I need to do dd/mm/yyyy - I accidentally ignored my mistake within my error message. How would I switch your regex around to use dd/mm/yyyy instead of mm/dd/yyyy