Validation::maxLength PHP Method

maxLength() public static method

public static maxLength ( $value, $length )
    public static function maxLength($value, $length)
    {
        $value_length = strlen($value);
        return $value_length <= $length;
    }

Usage Example

 /**
  * answerValidation 登録内容の正当性
  *
  * @param object &$model use model
  * @param array $data Validation対象データ
  * @param array $question 登録データに対応する項目
  * @param array $allAnswers 入力された登録すべて
  * @return bool
  */
 public function answerTextValidation(&$model, $data, $question, $allAnswers)
 {
     if (!in_array($question['question_type'], $this->_textValidateType)) {
         return true;
     }
     $ret = true;
     // 数値型登録を望まれている場合
     if ($question['question_type_option'] == RegistrationsComponent::TYPE_OPTION_NUMERIC) {
         if (!Validation::numeric($data['answer_value'])) {
             $ret = false;
             $model->validationErrors['answer_value'][] = __d('registrations', 'Number required');
         }
         if ($question['is_range'] == RegistrationsComponent::USES_USE) {
             $rangeRes = Validation::range($data['answer_value'], intval($question['min']), intval($question['max']));
             if (!$rangeRes) {
                 $ret = false;
                 $model->validationErrors['answer_value'][] = sprintf(__d('registrations', 'Please enter the answer between %s and %s.'), $question['min'], $question['max']);
             }
         }
     } else {
         if ($question['is_range'] == RegistrationsComponent::USES_USE) {
             if (!Validation::minLength($data['answer_value'], intval($question['min'])) || !Validation::maxLength($data['answer_value'], intval($question['max']))) {
                 $ret = false;
                 $model->validationErrors['answer_value'][] = sprintf(__d('registrations', 'Please enter the answer between %s letters and %s letters.'), $question['min'], $question['max']);
             }
         }
     }
     return $ret;
 }
All Usage Examples Of Validation::maxLength