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

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

 



On Thursday 30 March 2006 16:49, Arie Nugraha wrote:
> try this :
>
> $date = "30/12/1982 15:30"
>
> if (preg_match("/\d{2}\/\d{2}\/\d{4}\s\d{2}:\d{2}/i",$date )) {
>     echo "Date is valid";
> } else {
>     echo "Date NOT valid";
> }

This is not correct since you don't check the ranges of the day digits, month 
digits, etc.
The easiest way to check the string is to explode it by " " (space), then 
explode the first part by slash and the second by column, and at last check 
the ranges.
A regular expression will be much more complex.

>
> hope it will help you

-- 

Cyberly yours,
Petar Nedyalkov
Devoted Orbitel Fan :-)

PGP ID: 7AE45436
PGP Public Key: http://bu.orbitel.bg/pgp/bu.asc
PGP Fingerprint: 7923 8D52 B145 02E8 6F63 8BDA 2D3F 7C0B 7AE4 5436

Attachment: pgpoiQCiRaGO1.pgp
Description: PGP signature


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

  Powered by Linux