For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > March 2006 > Re: [PHP-DB] [Regular expression] Format string to "DD/MM/YYYY hh:mm"









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PHP-DB] [Regular expression] Format string to "DD/MM/YYYY hh:mm"
Balazs Hegedus

2006-03-31, 3:57 am

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 =3D '30/03/2983 12:00';
> $pattern =3D '[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) =3D=3D=3D 1) {
> echo 'date is in valid form';
> }
> else {
> echo 'date form is invalid';
> }
>
> ?>
>
> Hope it helps,
>
> Balazs
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com