public function lengthBetween($field, array $range, $message = null, $when = null)
    {
        if (count($range) !== 2) {
            throw new InvalidArgumentException('The $range argument requires 2 numbers');
        }
        $extra = array_filter(['on' => $when, 'message' => $message]);

        return $this->add($field, 'lengthBetween', $extra + [
            'rule' => ['lengthBetween', array_shift($range), array_shift($range)],
        ]);
    }
public function lengthBetween($field, array $range, $message = null, $when = null)
    {
        if (count($range) !== 2) {
            throw new InvalidArgumentException('The $range argument requires 2 numbers');
        }
        $extra = array_filter(['on' => $when, 'message' => $message]);

        return $this->add($field, 'lengthBetween', $extra + [
            'rule' => ['lengthBetween', array_shift($range), array_shift($range)],
        ]);
    }
public function lengthBetween ( $ field , array $ range , $ message = null , $ when = null ) { if ( count ( $ range ) !== 2 ) { throw new InvalidArgumentException ( 'The $range argument requires 2 numbers' ) ; } $ extra = array_filter ( [ 'on' => $ when , 'message' => $ message ] ) ; return $ this -> add ( $ field , 'lengthBetween' , $ extra + [ 'rule' => [ 'lengthBetween' , array_shift ( $ range ) , array_shift ( $ range ) ] , ] ) ; }
Add an rule that ensures a string length is within a range.

@param string $field The field you want to apply the rule to.
@param array $range The inclusive minimum and maximum length you want permitted.
@param string|null $message The error message when the rule fails.
@param string|callable|null $when Either 'create' or 'update' or a callable that returns
true when the validation rule should be applied.
@see \Cake\Validation\Validation::alphaNumeric()
@return $this
Add an rule that ensures a string length is within a range .