So i have a pretty basic form validator that checks if the field is valid but i'm having hard time trying to implement rules. i have already implemented a few rules but how can i implement max_length and min_length?
here is my validate function
public function validate($field,$value,$rules)
{
$field = ucfirst($field);
$rules = explode('|',$rules);
foreach($rules as $rule)
{
switch($rule)
{
case 'required':
$this->shouldBeRequired($field, $value);
break;
case 'string':
$this->shouldBeString($field,$value);
break;
case 'email':
$this->shouldBeEmail($field, $value);
break;
case 'number':
$this->shouldBeNumber($field,$value);
// default:
// throw new ErrorException("$rule doesn't exist");
}
}
}
i want to do case 'max_length' but i have no idea how. the rule should look like this max_length:60|required any help is appreciated