protected function _validateLength(AnConfig $config)
    {
        $property = $config->property;
        $value = $config->value;
        $entity = $config->entity;
        $options = AnConfig::unbox($config->options);

        //if a number is just passed then treat it as max
        if (!is_array($options)) {
            $options = array('max' => $options);
        }

        if ($property->isAttribute() && $property->isScalar()) {

            $options = AnConfig::unbox($options);

            if (is_array($options)) {
                //check the min/max length
                if (isset($options['max']) || isset($options['min'])) {

                    if (isset($options['max'])) {

                        $greater = AnHelperString::strlen($value) > (int) $options['max'];

                        if ($greater) {

                            $entity->addError(array(
                                'message' => sprintf(
                                    AnTranslator::_('%s %s can not be greater than %d characters'),
                                    $this->getIdentifier()->name,
                                    $property->getName(),
                                    $options['max']
                                ),
                                'code' => AnError::INVALID_LENGTH,
                                'key' => $property->getName(),
                                'max_lenght' => $options['max'],
                            ));

                            return false;
                        }
                    }

                    if (isset($options['min'])) {

                        $lesser = AnHelperString::strlen($value) < (int) $options['min'];

                        if ($lesser) {

                            $entity->addError(array(
                                'message' => sprintf(
                                    AnTranslator::_('%s %s can not be less than %d characters'),
                                    $this->getIdentifier()->name,
                                    $property->getName(),
                                    $options['min']
                                ),
                                'code' => AnError::INVALID_LENGTH,
                                'key' => $property->getName(),
                                'min_length' => $options['min'],
                            ));

                            return false;
                        }
                    }
                }
            } else {

                if (AnHelperString::strlen($value) != (int) $options) {

                    $entity->addError(array(
                        'message' => sprintf(
                            AnTranslator::_('%s %s must be %d characters'),
                            $this->getIdentifier()->name,
                            $property->getName(),
                            $options
                        ),
                        'code' => AnError::INVALID_LENGTH,
                        'key' => $property->getName(),
                        'length' => (int) $options,
                    ));

                    return false;
                }
            }
        }

        return true;
    }