/** * Validates the input value according to this attribute * * @param Input $input The input to validate * * @return boolean|string True if its valid, string with the error if not */ public static function validate(Input $input) { $value = $input->val(); //File if ($input->attr('type') === 'file') { $value = isset($value['name']) && !empty($value['size']) ? $value['name'] : null; } $attr = $input->attr('required'); return empty($attr) || !empty($value) || strlen($value) > 0 ? true : sprintf(static::$error_message, $attr); }
/** * Validates the input value according to this attribute * * @param Input $input The input to validate * * @return boolean|string True if its valid, string with the error if not */ public static function validate(Input $input) { $value = $input->val(); //File if ($input->attr('type') === 'file') { $value = isset($value['name']) ? $value['name'] : null; } $attr = str_replace('/', '\\/', $input->attr('pattern')); return empty($attr) || empty($value) || filter_var($value, FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => "/^{$attr}\$/"))) ? true : sprintf(static::$error_message, $attr); }
/** * Validates the input value according to this attribute * * @param Input $input The input to validate * * @return boolean|string True if its valid, string with the error if not */ public static function validate(Input $input) { $value = $input->val(); if (empty($value['tmp_name'])) { return true; } $attr = $input->attr('accept'); $accept = array_map('trim', explode(',', $attr)); $filename = $value['tmp_name']; $finfo = finfo_open(FILEINFO_MIME_TYPE); $mime = finfo_file($finfo, $filename); finfo_close($finfo); return array_search($mime, $accept) !== false ? true : sprintf(static::$error_message, $attr); }
/** * Validates the datetime input value according to this attribute * * @param Input $input The input to validate * * @return boolean|string True if its valid, string with the error if not */ public static function validateDatetime(Input $input) { $value = $input->val(); $attr = $input->attr('min'); return empty($attr) || strtotime($value) >= strtotime($attr) ? true : sprintf(static::$error_message, $attr); }
/** * Validates the input value according to this attribute * * @param Input $input The input to validate * * @return boolean|string True if its valid, string with the error if not */ public static function validate(Input $input) { $value = $input->val(); $attr = $input->attr('maxlength'); return empty($attr) || strlen($value) <= $attr ? true : sprintf(static::$error_message, $attr); }