note 89331 added to function.checkdate

From: Date: Tue, 03 Mar 2009 19:23:50 +0000
Subject: note 89331 added to function.checkdate
Groups: php.notes 
Request: Send a blank email to php-notes+get-151415@lists.php.net to get a copy of this message
While trying to validate user input in an easy way, I came up with this idea: convert user input using strtotime, then convert back using desired format to validate with and compare. Of course you could change it to use time as well. Hope you find it useful: <?php $input = '2009-03-03'; $date_format = 'Y-m-d'; $time = strtotime($input); echo "Is valid? " date($date_format, $time) != trim($input); ?> ---- Server IP: 190.2.55.64 Probable Submitter: 190.16.232.71 ---- Manual Page -- http://www.php.net/manual/en/function.checkdate.php Edit -- https://master.php.net/note/edit/89331 Del: integrated -- https://master.php.net/note/delete/89331/integrated Del: useless -- https://master.php.net/note/delete/89331/useless Del: bad code -- https://master.php.net/note/delete/89331/bad+code Del: spam -- https://master.php.net/note/delete/89331/spam Del: non-english -- https://master.php.net/note/delete/89331/non-english Del: in docs -- https://master.php.net/note/delete/89331/in+docs Del: other reasons-- https://master.php.net/note/delete/89331 Reject -- https://master.php.net/note/reject/89331 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#151415) next »