Re: [Regular expression] Format string to "DD/MM/YYYY hh:mm"
| From: | Balazs Hegedus | Date: | Fri, 31 Mar 2006 07:08:15 +0000 |
| Subject: | Re: [Regular expression] Format string to "DD/MM/YYYY hh:mm" | ||
| References: | 1 2 3 4 5 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-41646@lists.php.net to get a copy of this message | ||
Oops, \s matches any whitespace character, so if you need only space
there you should change \s to space (this way it matches tab too).
Balazs
2006/3/31, Balazs Hegedus <balazs.hegedus@gmail.com>:
> 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
>