PHP kôd:
class Validator
{
public function process()
{
if (strpos($rules, 'min=') !== false)
{
$num = $this->min($var, $rules);
if (is_numeric($num))
{
$this->errors[] = "should have at least $num characters!";
} elseif ($num === false)
{
$this->errors[] = 'Invalid rule.';
}
}
}
private function min($var, $rules)
{
preg_match('%min=([0-9]{1,10})%', $rules, $matches);
if (empty($matches[1]))
return false;
return strlen($var) < (int)$matches[1] ? $matches[1] : true;
}
}
$validator = (new Validator($vars))->process();
Ovako nešto, nadam se da shvataš.