$fname = "Kevin";

$fname_match = preg_match('/^[A-Za-z]{2,20}$/', $fname);

if($fname_match==true)
{
echo "All matches... true?";
}
else
{
echo "All matches.. noo?";
}


I should be getting the first one right?
But i get the else message....
Why?
'Kevin' should match?

preg_match() returns the number of times pattern matches. That will be either 0 times (no match) or 1 time because preg_match() will stop searching after the first match...

http://php.net/manual/en/function.preg-match.php

try simply if($fname_match) Or if you want to be more "clear": if($fname_match > 0)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.