andyd34 Posted March 1, 2011 Share Posted March 1, 2011 is the a way to tell is a submitted field is in date format mm/dd/yyyy or timestamp Link to comment https://forums.phpfreaks.com/topic/229194-is_date-or-is_timestamp/ Share on other sites More sharing options...
mhodge_txs Posted March 3, 2011 Share Posted March 3, 2011 You need to make use of the preg_match function using an expression. '/^[0-2]{2}\/[0-9]{2}\/[0-9]{4}$/' means the following: /^ = from the start of the string [0-9]{2} = look for 2 consecutive numbers between 0 and 9 (for the months) \/ = look for a "/" [0-9]{2} = look for 2 consecutive numbers between 0 and 9 (for the days) \/ = look for a "/" [0-9]{4} = look for 4 consecutive numbers between 0 and 9 (for the years) $/ = till the end of the string Beware however that this will validate FORMAT ONLY. i.e 99/99/9999 will pass as a valid format, but its not a valid date. <?php $dateFormatToValidate = "01/01/2010"; if(preg_match('/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/', $dateFormatToValidate)){ // is valid format, but might not necessarily be a valid date do further checking // ie. could be the 30th Feb..... }else{ // not valid } ?> Link to comment https://forums.phpfreaks.com/topic/229194-is_date-or-is_timestamp/#findComment-1182257 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.