*/ class LSformRule_rangelength extends LSformRule { // CLI parameters autocompleters protected static array $cli_params_autocompleters = array( 'limits' => null, ); /** * Validate form element value * * @param mixed $value The value to validate * @param array $options Validation options: * - Minimum length : $options['params']['limits'][0] * - Maximum length : $options['params']['limits'][1] * @param LSformElement &$formElement The related LSformElement object * * @return boolean True if value is valid, False otherwise */ public static function validate($value, $options, &$formElement) { $limits = LSconfig :: get('params.limits', null, null, $options); if(!is_array($limits) || count($limits) != 2) { LSerror :: addErrorCode('LSformRule_01',array('type' => 'rangelength', 'param' => 'limits')); return false; } $len = strlen($value); if ($len < $limits[0]) throw new LSformRuleException( getFData(_('Value is too short (minimum: %{limit}).'), $limits[0]) ); if ($len > $limits[1]) throw new LSformRuleException( getFData(_('Value is too long (maximum: %{limit}).'), $limits[1]) ); return True; } }