newbie. preg_match() error,

newbie. preg_match() error,

am 14.08.2007 12:55:34 von vivek.j.joshi

Hello,
I am trying to create a function that will match only valid date in mm/
dd format. (Month in, 01, 02, ..., 09, 10, 11, 12 and Dates in 01,
02, ..., 11, 12, ..., 30, 31).

I am trying this code, but it fails to work.

The error is :-
PHP Warning: preg_match(): Compilation failed: unmatched parentheses
at offset 15 in /home/wizard/regexDateTime.php on line xx

The code is here.
$test = '03/02';

$testPattern = '#[(0[1-9]|1[012])/(0[1-9]|[12][0-9]|3[01])]#';

if (preg_match($testPattern, $test)) // fails here
{
echo 'testPattern did not match';
}
else
{
echo 'testPattern matched';
}

echo "\nExiting.\n";
?>

Re: newbie. preg_match() error,

am 14.08.2007 13:01:06 von luiheidsgoeroe

On Tue, 14 Aug 2007 12:55:34 +0200, wizard wro=
te:

> Hello,
> I am trying to create a function that will match only valid date in mm=
/
> dd format. (Month in, 01, 02, ..., 09, 10, 11, 12 and Dates in 01,
> 02, ..., 11, 12, ..., 30, 31).
>
> I am trying this code, but it fails to work.
>
> The error is :-
> PHP Warning: preg_match(): Compilation failed: unmatched parentheses
> at offset 15 in /home/wizard/regexDateTime.php on line xx
>
> The code is here.
> > $test =3D '03/02';
>
> $testPattern =3D '#[(0[1-9]|1[012])/(0[1-9]|[12][0-9]|3[01])]#=
';
---------------------------^-------------------------------- --------^

remove the blockquotes there (possibly replace them with ^ and =

$ respectively).
-- =

Rik Wasmus

Re: newbie. preg_match() error,

am 14.08.2007 13:43:12 von vivek.j.joshi

It works like a charm, thanks a lot friend.

On Aug 14, 4:01 pm, Rik wrote:
> On Tue, 14 Aug 2007 12:55:34 +0200, wizard wrote:
> > Hello,
> > I am trying to create a function that will match only valid date in mm/
> > dd format. (Month in, 01, 02, ..., 09, 10, 11, 12 and Dates in 01,
> > 02, ..., 11, 12, ..., 30, 31).
>
> > I am trying this code, but it fails to work.
>
> > The error is :-
> > PHP Warning: preg_match(): Compilation failed: unmatched parentheses
> > at offset 15 in /home/wizard/regexDateTime.php on line xx
>
> > The code is here.
> > > > $test = '03/02';
>
> > $testPattern = '#[(0[1-9]|1[012])/(0[1-9]|[12][0-9]|3[01])]#';
>
> ---------------------------^-------------------------------- --------^
>
> remove the blockquotes there (possibly replace them with ^ and
> $ respectively).
> --
> Rik Wasmus