Re: [Regular expression] Format string to "DD/MM/YYYY hh:mm"
| From: | Balazs Hegedus | Date: | Fri, 31 Mar 2006 06:59:00 +0000 |
| Subject: | Re: [Regular expression] Format string to "DD/MM/YYYY hh:mm" | ||
| References: | 1 2 3 4 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-41645@lists.php.net to get a copy of this message | ||
Hi,
this regex isn't perfect at all but might do the job. You should
modify the pattern to match the year part against 2037 as a maximum
and also don't forget to checkdate().
<?php
$date = '30/03/2983 12:00';
$pattern = '[0-3][0-9]/[0|1][0-9]/[1|2][0-9]{3,3}\s[0-2][0-9]:[0-5][0-9]';
if (preg_match("!^$pattern$!", $date) === 1) {
echo 'date is in valid form';
}
else {
echo 'date form is invalid';
}
?>
Hope it helps,
Balazs