preg_match isn't working the way I want it to.
Posted: Fri Dec 17, 2010 8:02 pm
I have some code.
Basically I'm trying to devise a way to do a general check of all the form fields that are passed into this function. preg_match() doesn't seem to be working the way it should. Does preg_match return a boolean TRUE or FALSE or what? I've tried /[A-Za-z0-9{x}/ but that doesn't seem to be working the way that it should. Please help me with this thanks.
Code: Select all
function Validation($var,$minlength,$maxlength)
{
$String_Length = strlen($var);
$Parameter_Name = array_search($var, $GLOBALS);
print "$Parameter_Name";
$Check_String = preg_match("/[a-zA-Z0-9]{2,4}/",$var);
if($String_Length > $minlength AND $String_Length < $maxlength)
{
if($var != NULL AND $Check_String == TRUE)
{
addslashes($var);
return 1;
}
else {return 2;}
}
else
{return 3;}
}