On Tuesday 01 April 2003 02:47 pm, Jon Haworth wrote:
> Hi Siva,
>
> > checkdate function verifies whether the date is valid or
> > not by taking month, day and year as arguments.
> > The problem is when someone enters a three digit year by
> > mistake (200 instead of 2003), this function does not catch it.
>
> Yes, I've been bitten by this as well :-)

Thanks Jon. Infact, we caught it when one of our guys were testing the 
application internally. Thankfully no serious problem :-)

>
> > We are separating the year part from the string and validating
> > separately to solve this problem. Is there a better way to do it?
>
> I think you're stuck with the extra validation step, but you can do it
> quite neatly with a replacement function that looks something like this:
>
> function myCheckdate ($m, $d, $y, $min = 1900, $max = 2100)
> {
>
>   // check whether $y is within allowable range
>   if ($y <= $min || $y >= $max)
>     return false;
>
>   // the year is OK: checkdate can do its stuff
>   return (checkdate($m, $d, $y))
>
> }

Your suggestions looks very neat, we will use that. Thanks once again. 

>
> You can adjust the default allowable years to match what you usually need,
> and then override them as necessary.
>

> Personally I'd like to see PHP's checkdate() work a bit like the one above,
> or maybe have checkReasonableDate() and checkImprobableDate(): I'm prepared
> to believe that some PHP developers need to validate three- and five- digit
> years, but I can't believe that it's *that* common :-)

I too feel taht it will be nice to have another PHP function which does this 
work. I assume that the current function is needed by some applications 
(historical, archeoligacal etc) which account very early years and possibly 
years far into the future.

Siva





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to