/*
* Validate the MySQL Timestamp
*
* @author Junaid Atari <mj.atari@gmail.com>
* @version 1.0
* @param string $str MySQL Timestamp to check
* @return bool TRUE on valid | FALSE
*/
function isValidMySqlTimeStamp ( $str )
{
/* PCRE Pattern written by Junaid Atari */
if ( !preg_match ( '/^(?<y>19\d\d|20\d\d)\-(?<m>0[1-9]|1[0-2])\-' .
'(?<d>0\d|[1-2]\d|3[0-1]) (?<h>0\d|1\d|2[0-3]' .
')\:(?<i>[0-5][0-9])\:(?<s>[0-5][0-9])$/',
$str, $date ) )
return false;
return checkdate ( $date['m'], $date['d'], $date['y'] );
}
/*
+-----------+
| Example |
+-----------+
*/
var_dump ( isValidMySqlTimeStamp ( '2011-11-26 11:25:26' ) );
/*
+-----------+
| Output |
+-----------+
*/
# Output: True
* Validate the MySQL Timestamp
*
* @author Junaid Atari <mj.atari@gmail.com>
* @version 1.0
* @param string $str MySQL Timestamp to check
* @return bool TRUE on valid | FALSE
*/
function isValidMySqlTimeStamp ( $str )
{
/* PCRE Pattern written by Junaid Atari */
if ( !preg_match ( '/^(?<y>19\d\d|20\d\d)\-(?<m>0[1-9]|1[0-2])\-' .
'(?<d>0\d|[1-2]\d|3[0-1]) (?<h>0\d|1\d|2[0-3]' .
')\:(?<i>[0-5][0-9])\:(?<s>[0-5][0-9])$/',
$str, $date ) )
return false;
return checkdate ( $date['m'], $date['d'], $date['y'] );
}
/*
+-----------+
| Example |
+-----------+
*/
var_dump ( isValidMySqlTimeStamp ( '2011-11-26 11:25:26' ) );
/*
+-----------+
| Output |
+-----------+
*/
# Output: True
0 comments:
Post a Comment