-
php date validation
I'm building a php form and just want to test a field to see if the date is in the proper format without using a function...
I know just enough php to get the form working...other than this...got the testing for a proper e-mail address working, but can't get this to work...
I've tried this, but it's not working...anyone? The format should be MM/DD/YYYY
Code:
$result=preg_match("/^(\d{2})/(\d{2})/(\d{4})$/",$date);
if(!$result){
echo "Enter a valid date";
exit;
}
I also tried:
Code:
$result=ereg("^(\d{2})/(\d{2})/(\d{4})+$",$date);
but I don't know enough about what the punctuation symbols ^,/,(,{ and [ represent to get it working correctly...
version 4.4.7
TIA
-
Try this:
PHP Code:
<?PHP
$date = "01/01/2008";
$result = preg_match("/^[0-9]{2}\/[0-9]{2}\/[0-9]{4}$/",$date);
if(!$result){
echo "Enter a valid date";
exit;
}
?>
-
Hi,
so 13/13/2009 is a valid date?
Musicman