PDA

View Full Version : eregi - numeric and alphabetic only


Phip
12-01-2002, 03:37 AM
no matter how had i try i can never figure out regular expressions. anyway, this is very simple but i can't get it. why doesn't this work? i want $title to only have numeric and alphabetic charaters

if(!eregi("[a-z0-9]", $title))
{
echo "bad";
}

Phip
12-01-2002, 08:11 PM
Okay well, if anyone else wants to know the answer i figured it out.

$title = "hey batman let's go!";

if(ereg('[^a-zA-Z0-9 ]', $title))
{
echo "bad";
}
else
{
echo "good";
}

returns true becuse there is a "'" and a "!" in the string.


i was just doing the matching backwards.