Hi !
1st : Tell us what you want from this script: I suppose it's : make someone enter a date until what he/she types is a "good" date (in "good" format). right ? If yes, you loop until the entry is OK ? 2nd : the format you show is not clear : It could be : 2008, January the 1st 2001, January the 8th, ... and so on It should be better to write it MM-DD-YY (for month, day, year). (FYI + :I'm french and we display dates as DD/MM/YY) for this format, the regex "could" be: (0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])-\d\d but : it ignores that the maximum number of days depends on the month( +28,29,30,31), it ignores leap years (February 28th or 29 th ?) You should use the function "timelocal()" from the standard module "Time::Local" : try to transform the date you have to validate into a +n "epoch" time (as the function time() returns) : if the function fai +ls, the date is wrong : this script seems to work: use Time::Local timelocal; my ($m,$d,$y); do { my $date; print "date (MM-DD-YY) ? "; $date=<>; chomp($date); ($m,$d,$y)=split(/-/,$date); $m -= 1; $y += 1900; } until(timelocal(0,0,0,$d,$m,$y));
I hope it adresses your need and will help you

In reply to Re: Regular expression for date by didess
in thread Regular expression for date by perlee

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.