13 public function validate($string, $config, $context) {
15 $string = trim($string);
16 if ($string ===
'')
return false;
19 if ($parent_result !==
false)
return $parent_result;
21 $length = strlen($string);
22 $last_char = $string[$length - 1];
24 if ($last_char !==
'%')
return false;
26 $points = substr($string, 0, $length - 1);
28 if (!is_numeric($points))
return false;
30 $points = (int) $points;
32 if ($points < 0)
return '0%';
33 if ($points > 100)
return '100%';
35 return ((
string) $points) .
'%';