Verifying date format in PHP
There are several ways to check the format of a date in PHP; the simplest method is to make use regular expressions.
To confirm a date format DD/MM/YYYY, where the days and/or month can be given as single number:
<?php
function testDate( $value )
{
return preg_match( '`^\d{1,2}/\d{1,2}/\d{4}$`' , $value ) )
}
testDate( '21/11/1999' ); // -> true
testDate( '3/9/2008' ); // -> true
testDate( 'a/04/2003' ); // -> false
testDate( '28-01-2000' ); // -> false
testDate( '99/13/1978' ); // -> true
?>
Note that:
As the last call, this function does not check the validity of the date itself but only the validity of its format.
See also:
Useful links for PHP