what might be easier than usign that huge ugly regular expression is if you first break up your keywords
I have not tested any of this so it still might need a slight amount of tweaking but this should give you the idea you need to get going from here. If you want to get rid of ALL spaces not just trim a keyword then replace the
$keywords[$i] = trim($keywords[$i]); with this instead
$keywords[$i] = ereg_replace(" ",$keywords[$i]);
//this will seperate every keyword into an array
$keywords = explode("," , $string);
//next let's trim any whitespace
for ($i=0; $i<sizeOf($keywords); $i++)
$keywords[$i] = trim($keywords[$i]);
$i = 0;
$validKeyWord = true;
while (sizeOf($keywords) < $i && $validKeyWord)
{
if (ereg("^([a-z]+)|[0-9]{2,2})$", $keyword[$i++]))
$validKeyWord= false
}
if ($validKeyWord)
{
if (sizeOf($keywords) > 2)
{
echo "error! you are limited to only 2 keywords";
do_something_with_this_function($keywords);
}
else
{
echo "you have 2 keywords or less, good job";
do_whatever_your_site_does_with_keywords($keywords);
}
}
else
{
echo "you did not enter a proper keyword, please try again";
}