Team:

I have a date which comes in the format of mm/dd/yy.
Example: 08/01/00

Now, I have my regular expression to check for this in this
format.

Example:
$result = $start_date =~ /(\d\d)\/(\d\d)\/(\d\d)/;

So, when I enter a date in the format of 08/01/00,
the result is success, or a non-zero return coded.

Now, if I enter a date in the format of 88888/01/00, the $result is STILL success, or a non-zero value.

Is there something which will ensure each field is only two(2) digits in length? Otherwise I want to print an exception message any have them retry again.

Thanks much!

TEAM:

I get the "Well Dohh...!!" award.....!!!!:$

I discovered the "Quantified Subpattern Operator - {}".

Example:
$result = $start_date =~ /(\d\d){2}\/(\d\d){2}\/(\d\d){2}/;

This ensures that the size of the digit field cannot exceed two(2) digits.

Thanks..!!!

Team:

I have a date which comes in the format of mm/dd/yy.
Example: 08/01/00

Now, I have my regular expression to check for this in this
format.

Example:
$result = $start_date =~ /(\d\d)\/(\d\d)\/(\d\d)/;

So, when I enter a date in the format of 08/01/00,
the result is success, or a non-zero return coded.

Now, if I enter a date in the format of 88888/01/00, the $result is STILL success, or a non-zero value.

Is there something which will ensure each field is only two(2) digits in length? Otherwise I want to print an exception message any have them retry again.

Thanks much!

OK Guys, There must have been a SOLAR FLARE.....

This worked fine just a few moments ago. Now, it won't work at all....

What gives....?????

what you really want are string anchors (^$):

$result = $start_date =~ /^\d\d\/\d\d\/\d\d$/;

the way you are doing it is checking a sub string, so dd/dd/dd anywhere in the string would match (where "d" is a single digit)

btw,

this: (\d\d){2}

translates to two digits ina row twice \d\d\d\d

you wanted:

\d{2}\/\d{2}\/\d{2}

btw,

this: (\d\d){2}

translates to two digits ina row twice \d\d\d\d

you wanted:

\d{2}\/\d{2}\/\d{2}

Kevin:

The solution worked "Flawlessly......." I knew it was something

btw,

this: (\d\d){2}

translates to two digits ina row twice \d\d\d\d

you wanted:

\d{2}\/\d{2}\/\d{2}

Kevin:

The solution worked "Flawlessly......." I knew it was something
simple. :| Anyway, thanks again as always to you and the
group......

Kevin:

The solution worked "Flawlessly......." I knew it was something

Okay. This is got to be the craziest thing in my 20+years in IT.

Here are the inputs....
********************************************
ERROR: ENDING DATE is INVALID
ERROR:==> " 111/111/111 " :)
********************************************
Please ENTER the ENDING DATE in the FORMAT of ---> mm/dd/yy
winv:==> 111/11/11
WHILE-LOOP RESULT CODE:==> 1:angry:
WHILE-LOOP END DATE:==> 111/11/11

Notice it BYPASSED the incorrect month size of "111", but when it saw the "11" and "11" it set the result to TRUE or the condition of the REGEX was successful.

Ok. Now I was under the impression that:

$result = $end_date =~ /\d{2}\/\d{2}\/\d{2}/;

meant that if ANY of the fields ARE LARGER that two(2)digits, you fail.........


Okay...I am lost on this

what you really want are string anchors (^$):

$result = $start_date =~ /^\d\d\/\d\d\/\d\d$/;

the way you are doing it is checking a sub string, so dd/dd/dd anywhere in the string would match (where "d" is a single digit)

If I had been "PAYING ATTENTION......:| ", I would have noticed the fact that I NEEDED TO USE STRING ANCHORS......!!!!!!!!:$

Ok. finished the test.

PHASE-1: Obtaining Date Range Information
Please ENTER the STARTING DATE in the FORMAT of ---> mm/dd/yy
winv:==> 111/11/11
----->RESULT:==> 0
----->DATE:===> 111/11/11
********************************************
ERROR: STARTING DATE is INVALID
ERROR:==> " 111/11/11 "
********************************************
Please ENTER the STARTING DATE in the FORMAT of ---> mm/dd/yy
winv:==> 11/111/11
WHILE LOOP ReSULT:==> 0
WHILE LOOP START DATE:==> 11/111/11
********************************************
ERROR: STARTING DATE is INVALID
ERROR:==> " 11/111/11 "
********************************************
Please ENTER the STARTING DATE in the FORMAT of ---> mm/dd/yy
winv:==> 08/01/00
WHILE LOOP ReSULT:==> 1
WHILE LOOP START DATE:==> 08/01/00
Please ENTER the END-DATE in the FORMAT of ---> mm/dd/yy
winv:==> 111/11/11
RESULT CODE:==> 0
END DATE:==> 111/11/11
********************************************
ERROR: ENDING DATE is INVALID
ERROR:==> " 111/11/11 "
********************************************
Please ENTER the ENDING DATE in the FORMAT of ---> mm/dd/yy
winv:==> 11/11/1111
WHILE-LOOP RESULT CODE:==> 0
WHILE-LOOP END DATE:==> 11/11/1111
********************************************
ERROR: ENDING DATE is INVALID
ERROR:==> " 11/11/1111 "
********************************************
Please ENTER the ENDING DATE in the FORMAT of ---> mm/dd/yy
winv:==> 08/01/00
WHILE-LOOP RESULT CODE:==> 1
WHILE-LOOP END DATE:==> 08/01/00

We are "Good to Go....!!!!!"

Thanks Kev....!!!


Works great.....

where do I send my invoice? ;)


PS.... use the code tags to display code.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.