/*
* Validate the MySQL Date
*
* @author Junaid Atari <mj.atari@gmail.com>
* @version 1.0
* @param string $str MySQL Date to check
* @return bool TRUE on valid | FALSE
*/
function isValidMySqlDate ( $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])$/', $str, $date ) )
return false;
return checkdate ( $date['m'], $date['d'], $date['y'] );
}
/*
+-----------+
| Example |
+-----------+
*/
var_dump ( isValidMySqlDate ( '2011-11-22' ) );
/*
+-----------+
| Output |
+-----------+
*/
# Output: True
* Validate the MySQL Date
*
* @author Junaid Atari <mj.atari@gmail.com>
* @version 1.0
* @param string $str MySQL Date to check
* @return bool TRUE on valid | FALSE
*/
function isValidMySqlDate ( $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])$/', $str, $date ) )
return false;
return checkdate ( $date['m'], $date['d'], $date['y'] );
}
/*
+-----------+
| Example |
+-----------+
*/
var_dump ( isValidMySqlDate ( '2011-11-22' ) );
/*
+-----------+
| Output |
+-----------+
*/
# Output: True
0 comments:
Post a Comment