Re: note 9672 added to ereg
| From: | Rasmus Lerdorf | Date: | Sat, 18 Nov 2000 01:10:57 +0000 |
| Subject: | Re: note 9672 added to ereg | ||
| References: | 1 | Groups: | php.general php.notes |
| Request: | Send a blank email to php-general+get-25978@lists.php.net to get a copy of this message | ||
On 18 Nov 2000 php-general@lists.php.net wrote:
> <?
> $date = "2000-12-999";
> if (eregi("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs))
> echo "Passed";
> else
> echo "Invalid";
> ?>
> Why would this echo out Passed? The last set of numbers is not 1 or 2 digits. It is 3.
Yes, but 2 is a subset of 3. You are not telling it to match only 1 or 2.
If you want to do that you need to add a $ to the end of that regex.
-Rasmus