Re: ereg function
| From: | CC Zona | Date: | Thu, 24 May 2001 17:29:15 +0000 |
| Subject: | Re: ereg function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-54252@lists.php.net to get a copy of this message | ||
In article <002e01c0e46c$ec2459a0$6e00a8c0@webdesign>,
jpaulson@lbjs.com ("Jay Paulson") wrote:
> echo ereg("^[a-zA-Z]$", $fname);
>
> as you can see I'm just looking to make sure the variable $fname just has
> characters a-zA-Z and nothing else.
Actually, you're checking whethere the variable is a single-character
string a-zA-Z. For what you want:
ereg("^[a-zA-Z]+$", $fname); //add plus sign
Note also that although the docs imply that ereg() returns an integer
value, it says further down "Returns true if a match for pattern was found
in string, or false if no matches were found or an error occurred." In my
experience, boolean values don't echo well. Try this instead:
if(ereg("^[a-zA-Z]+$", $fname))
{
echo "<p>Passed!</p>\n";
}
else
{
echo "<p>Failed. Enter a different value.</p>\n";
}
--
CC