function ($description, $value, $pattern, $minLength, $maxLength, $expected=0) {
$found = array();
$length = strlen($value);
if ($length < $minLength)
return "$description $this->tooShort: $length";
if ($length > $maxLength)
return "$description $this->tooLong: $length";
$matchResult = preg_match($pattern, $value, $found);
if ($matchResult === false)
return "error in pattern: $pattern";
if ($matchResult != $expected)
return "$description $this->invalid"
. ($expected ? '' : ": ". implode(' ', $found) );
return null; //valid
}
|