Re: [Regular expression] Format string to "DD/MM/YYYY hh:mm"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>:
> 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
>

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux