Re: regexp novice

From: Date: Thu, 17 May 2012 20:58:37 +0000
Subject: Re: regexp novice
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-317883@lists.php.net to get a copy of this message
Try this: /(0?[1-9]|[12][0-9]):?[0-5][0-9]/ FYI: ? is equal to {0,1}, and [1-9] to [123456789] (and therefore [1-2] to [12]). Am 17.05.2012 22:37, schrieb Jim Giner: > ok - finally had to come up with my own regexp - and am failing. > > Trying to validate an input of a time value in the format hh:mm, wherein > I'll accept anything like the following: > hmm > hhmm > h:mm > hh:mm > > in a 12 hour format. My problem is my test is ok'ing an input of 1300. > > Here is my test: > > if (0 == preg_match("/([0][1-9]|[1][0-2]|[1-9]):[0-5][0-9]/",$t)) > return true; > else > return false; > > Can someone help me correct my regexp? > > >

« previous php.general (#317883) next »