note 107510 deleted from function.checkdate by googleguy

From: Date: Tue, 22 Oct 2013 06:45:47 +0000
Subject: note 107510 deleted from function.checkdate by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-196626@lists.php.net to get a copy of this message
Note Submitter: Anonymous ---- This is a very good function to check if a date format is valid (with regex). For example: 2012-2-28 = Valid 2012-2-29 = Valid (leap year) 2012-2-30 = Invalid 2012-1-30 = Valid 2012-1-31 = Valid 2012-2-32 = Invalid Ensure there are no spaces in the preg_match function: <?php function Valid_Date_Format($date) { $converted=str_replace('/','-',$date); if(preg_match("/^((((19|20)(([02468][048])|([13579][26]))-02-29))|((20[0-9][0-9])|(19[0-9][0-9]))-((((0[1-9])| (1[0-2]))-((0[1-9])|(1\d)|(2[0-8])))|((((0[13578])|(1[02]))-31)|(((0[1,3-9])| (1[0-2]))-(29|30)))))$/",$converted)===1) { return TRUE; } return FALSE; } ?> I don't know where I got the original code from but I've not found anything better.

« previous php.notes (#196626) next »