You are here: Re: Best way to validate a date « PHP « IT news, forums, messages
Re: Best way to validate a date

Posted by Eli on 10/04/57 11:10

David Bevan wrote:
> Hi all,
>
> I'm looking to validate a date submitted through a
> form and I cannot decide which would be the best way
> to do it. The form of the date needs to be:
> YYYY-MM-DD.
> At the moment I'm torn between using a regex,
> something like: 20[\d][\d]-[0-1][\d]-[0-3][\d]
> or using the checkdate() function.
>
> Does anyone have any pros and/or cons to implement one
> method over the other or other methods you may have
> used?
>
> Thanks,
> David

Better use checkdate, since it checks if the date really exists (not
just well formatted).
Mabye do something like this:

list($check_year,$check_month,$check_day) = explode("-",$date);
if (checkdate($check_month,$check_day,$check_year))
echo "Date is valid";
else
echo "Date is not valid";

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация