in reply to Re: Quick Regex Question
in thread Quick Regex Question

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.

Replies are listed 'Best First'.
Re^3: Quick Regex Question
by Corion (Patriarch) on May 07, 2007 at 20:24 UTC

    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...

Re^3: Quick Regex Question
by suaveant (Parson) on May 07, 2007 at 20:30 UTC
    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
        Just switch before and after the first /
        /^(?:[01]\d\/[0-3]\d\/(?:19|20)\d\d)?$/
        But the test data you said you used was 03/30/2007 which is MM/DD/YYYY

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