RE: [PHP] Re: ereg size limit???
| From: | SP | Date: | Tue, 23 Apr 2002 01:22:13 +0000 |
| Subject: | RE: [PHP] Re: ereg size limit??? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-94095@lists.php.net to get a copy of this message | ||
Hey James, yeah you're right that was a typo, ereg was what I meant. Thanks
your suggestion worked and plus I think preg is much faster then ereg so
that's cool.
-----Original Message-----
From: liljim [mailto:liljim@liljim.co.uk]
Sent: April 22, 2002 4:44 AM
To: php-general@lists.php.net
Subject: [PHP] Re: ereg size limit???
Hi,
"Sp" <internetracer@yifan.net> wrote in message
news:NDBBJHKAELJNNJMBMFHDKEPJCOAA.internetracer@yifan.net...
> I am trying to validate my input with ereg but I get the error "Warning:
> REG_BADBR" when I try over 255 characters. Is there anyway around this?
>
> Works
> =====
> if(eregi('^[A-Za-z]{1,255}$', "test sentence"))
> echo "valid input";
>
> Doesn't Work
> ============
> if(eregi('^[A-Za-z]{1,256}$', "test sentence"))
> echo "valid input";
First off, you're using eregi (case insensitive), but defining a-zA-Z (a
through z, case insensitive) in your characters class. You could just use
ereg and leave the character class as it is, or drop the A-Z from the eregi
version.
Secondly, I'd amend your code to:
^[a-z]+$
And thirdly, I'd just use a combination of ereg / preg_* functions and
strlen.
if(preg_match("/^[a-z]+$/i", $string) && strlen($string) < 255)
{
echo "Whatever.";
}
I'm not sure why you're getting that error, but then again, I haven't
bothered reading up about it :)
James
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php