当前位置: 首页>>代码示例>>PHP>>正文


PHP Validation::appendMessage方法代码示例

本文整理汇总了PHP中Phalcon\Validation::appendMessage方法的典型用法代码示例。如果您正苦于以下问题:PHP Validation::appendMessage方法的具体用法?PHP Validation::appendMessage怎么用?PHP Validation::appendMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Phalcon\Validation的用法示例。


在下文中一共展示了Validation::appendMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: validate

 /**
  * Executes the validation
  *
  * @param Phalcon\Validation $validator
  * @param string $attribute
  * @return boolean
  */
 public function validate(\Phalcon\Validation $validator, $attribute)
 {
     $flag = true;
     $value = $validator->getValue($attribute);
     $errorCode = $this->getOption('code');
     if (!is_array($value)) {
         $message = '参数必须是数组';
         $validator->appendMessage(new Message($message, $attribute, 'Nums'));
         return false;
     }
     $countVal = count($value);
     $ruleMin = $this->getOption('min');
     $ruleMax = $this->getOption('max');
     if ($ruleMin == $ruleMax) {
         if ($countVal < $ruleMin) {
             $flag = false;
         }
     } else {
         if ($countVal < $ruleMin || $countVal > $ruleMax) {
             $flag = false;
         }
     }
     if (!$flag) {
         $message = $this->getOption('message');
         if (!$message) {
             $message = 'The num is not valid';
         }
         $validator->appendMessage(new Message($message, $attribute, 'Nums'));
         return false;
     }
     return true;
 }
开发者ID:nicklos17,项目名称:littlemall,代码行数:39,代码来源:NumsValidator.php

示例2: validate

 public function validate(Validation $validator, $attribute)
 {
     $value = $validator->getValue($attribute);
     $message = $this->getOption('message');
     if (!$message) {
         $message = '您填写的密码格式有误';
     }
     if (preg_match('/^[a-zA-Z0-9\\!\\@\\#\\$\\%\\^\\&\\*\\(\\)\\_\\+\\|\\~]{8,32}$/', $value) == 0) {
         $message = '您填写的密码格式有误,密码只能包含8-32个英文大小写字母、数字和以下符号:!@#$%^&*()_+|~,且不能全部由字母或数字组成。';
         $validator->appendMessage(new Message($message, $attribute));
         return false;
     }
     if (preg_match_all('/[0-9]/', $value) == strlen($value)) {
         $message = '您填写的密码格式有误,密码不能只包含数字。';
         $validator->appendMessage(new Message($message, $attribute));
         return false;
     }
     if (preg_match_all('/[a-z]/', $value) == strlen($value)) {
         $message = '您填写的密码格式有误,密码不能只包含英文小写字母。';
         $validator->appendMessage(new Message($message, $attribute));
         return false;
     }
     if (preg_match_all('/[A-Z]/', $value) == strlen($value)) {
         $message = '您填写的密码格式有误,密码不能只包含英文大写字母。';
         $validator->appendMessage(new Message($message, $attribute));
         return false;
     }
     return true;
 }
开发者ID:sieg1980,项目名称:pohome,代码行数:29,代码来源:Password.php

示例3: validate

 /**
  * Executes the validation
  *
  * @param Phalcon\Validation $validator
  * @param string $attribute
  * @return boolean
  */
 public function validate(\Phalcon\Validation $validator, $attribute)
 {
     $flag = true;
     $reqType = $validator->getValue($attribute);
     // 待校验的文件集合
     $fileType = $this->getOption('filetype');
     // 合法的文件类型集合
     $errorCode = $this->getOption('code');
     foreach ($reqType as $file) {
         $extArr = explode('.', $file);
         $ext = array_pop($extArr);
         if (!in_array($ext, $fileType)) {
             $flag = false;
             break;
         }
     }
     if (!$flag) {
         $message = $this->getOption('message');
         if (!$message) {
             $message = 'The filetype is not valid';
         }
         $validator->appendMessage(new Message($message, $attribute, 'filetype'));
         return false;
     }
     return true;
 }
开发者ID:nicklos17,项目名称:littlemall,代码行数:33,代码来源:FileTypeValidator.php

示例4: validate

 /**
  * @param \Phalcon\Validation $validation
  * @param string              $field
  *
  * @return boolean
  *
  * @throws \Phalcon\Validation\Exception
  */
 public function validate(\Phalcon\Validation $validation, $field)
 {
     if (!is_string($field)) {
         throw new \Phalcon\Validation\Exception("Field name must be a string");
     }
     $label = $this->getOption("label");
     if (empty($label)) {
         $label = $validation->getLabel($field);
     }
     $value = $validation->getValue($field);
     if ($this->isSetOption("allowEmpty") && empty($value)) {
         return true;
     }
     // http://stackoverflow.com/questions/1418423/the-hostname-regex
     if (!preg_match('/^(?=.{1,255}$)[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?(?:\\.[0-9A-Za-z](?:(?:[0-9A-Za-z]|-){0,61}[0-9A-Za-z])?)*\\.?$/', $value)) {
         $message = $this->getOption("message");
         if (empty($message)) {
             $message = "Field :field is not a valid hostname";
         }
         $replacePairs = [":field" => $label];
         $validation->appendMessage(new \Phalcon\Validation\Message(strtr($message, $replacePairs), $field, "Hostname"));
         return false;
     }
     return true;
 }
开发者ID:sidroberts,项目名称:phalcon-validators,代码行数:33,代码来源:Hostname.php

示例5: validate

 public function validate(Validation $validation, $attribute)
 {
     $value = $validation->getValue($attribute);
     $model = $this->getOption('model');
     $except = $this->getOption("except");
     if (empty($model)) {
         throw new \Exception("Model must be set");
     }
     if (empty($attribute)) {
         throw new \Exception("arrtibute must be set");
     }
     if ($except) {
         $number = $model::count(sprintf($attribute . " = %s AND " . $attribute . " != %s", $value, $except));
     } else {
         $number = $model::count(sprintf($attribute . " = %s", $value));
     }
     if (!$number) {
         $message = $this->getOption('message');
         if (empty($message)) {
             $message = '字段对应的值不存在';
         }
         $validation->appendMessage(new Message($message, $attribute, "Existence"));
         return false;
     }
     return true;
 }
开发者ID:huxiaohe,项目名称:api-framework,代码行数:26,代码来源:Existence.php

示例6: validate

 /**
  * {@inheritdoc}
  *
  * @param Validation $validation
  * @param string $attribute
  *
  * @return bool
  * @throws Exception
  */
 public function validate(Validation $validation, $attribute)
 {
     $value = $validation->getValue($attribute);
     $field = $this->getOption('label');
     if (empty($field)) {
         $validation->getLabel($attribute);
     }
     if (false === $this->hasOption('places')) {
         throw new Exception('A number of decimal places must be set');
     }
     if ($this->hasOption('digits')) {
         // Specific number of digits
         $digits = '{' . (int) $this->getOption('digits') . '}';
     } else {
         // Any number of digits
         $digits = '+';
     }
     if ($this->hasOption('point')) {
         $decimal = $this->getOption('point');
     } else {
         // Get the decimal point for the current locale
         list($decimal) = array_values(localeconv());
     }
     $result = (bool) preg_match(sprintf('#^[+-]?[0-9]%s%s[0-9]{%d}$#', $digits, preg_quote($decimal), $this->getOption('places')), $value);
     if (!$result) {
         $message = $this->getOption('message');
         $replacePairs = [':field' => $field];
         if (empty($message)) {
             $message = ':field must contain valid decimal value';
         }
         $validation->appendMessage(new Message(strtr($message, $replacePairs), $attribute, 'Decimal'));
         return false;
     }
     return true;
 }
开发者ID:phalcon,项目名称:incubator,代码行数:44,代码来源:Decimal.php

示例7: validate

 /**
  * Executes the validation
  *
  * @package     base-app
  * @version     2.0
  *
  * @param object $validation Phalcon\Validation
  * @param string $field field name
  *
  * @return boolean
  *
  * @throws \Phalcon\Validation\Exception
  */
 public function validate(\Phalcon\Validation $validation, $field)
 {
     $value = $validation->getValue($field);
     $model = $this->getOption("model");
     $attribute = $this->getOption("attribute");
     if (empty($model)) {
         throw new \Phalcon\Validation\Exception("Model must be set");
     }
     if (empty($attribute)) {
         $attribute = $field;
     }
     if ($except = $this->getOption('except')) {
         $number = $model::count(array($attribute . "=:value: AND " . $attribute . "!= :except:", "bind" => array("value" => $value, 'except' => $except)));
     } else {
         $number = $model::count(array($attribute . "=:value:", "bind" => array("value" => $value)));
     }
     if ($number) {
         $label = $this->getOption("label");
         if (empty($label)) {
             $label = $validation->getLabel($field);
             if (empty($label)) {
                 $label = $field;
             }
         }
         $message = $this->getOption("message");
         $replacePairs = array(":field" => $label);
         if (empty($message)) {
             $message = $validation->getDefaultMessage("Uniqueness");
         }
         $validation->appendMessage(new \Phalcon\Validation\Message(strtr($message, $replacePairs), $field, "Uniqueness"));
         return false;
     }
     return true;
 }
开发者ID:al35mm,项目名称:Phalcon-Rocket,代码行数:47,代码来源:Uniqueness.php

示例8: validate

 public function validate(\Phalcon\Validation $validator, $attribute)
 {
     $value = $validator->getValue($attribute);
     $size = $this->getOption('max');
     $max = Functions::bytes($size);
     if ($max != false) {
         if ($value['size'] > $max) {
             $validator->appendMessage(new Message('Превышен допустимый размер файла. Максимальный разрешённый размер - ' . $size . '.', $attribute, 'upload_size'));
             return false;
         }
         return true;
     } else {
         $validator->appendMessage(new Message('Неверный формат размера файла', $attribute, 'improperly_formatted_size'));
         return false;
     }
 }
开发者ID:atnartur,项目名称:SimpleBannerRotator,代码行数:16,代码来源:UploadSize.php

示例9: validate

 public function validate(\Phalcon\Validation $validation, $field)
 {
     $password = $validation->getValue($field);
     $error = FALSE;
     if (strlen($password) == 0) {
         $error = 'You must provide a password.';
     }
     $strength = 0;
     /*** get the length of the password ***/
     $length = strlen($password);
     /*** check if password is not all lower case ***/
     if (strtolower($password) != $password) {
         $strength += 1;
     }
     /*** check if password is not all upper case ***/
     if (strtoupper($password) != $password) {
         $strength += 1;
     }
     /*** check string length is 8 -15 chars ***/
     if ($length >= 8 && $length <= 15) {
         $strength += 1;
     }
     /*** check if lenth is 16 - 35 chars ***/
     if ($length >= 16 && $length <= 35) {
         $strength += 2;
     }
     /*** check if length greater than 35 chars ***/
     if ($length > 35) {
         $strength += 3;
     }
     /*** get the numbers in the password ***/
     preg_match_all('/[0-9]/', $password, $numbers);
     $strength += count($numbers[0]);
     /*** check for special chars ***/
     preg_match_all('/[|!@#$%&*\\/=?,;.:\\-_+~^\\\\]/', $password, $specialchars);
     $strength += sizeof($specialchars[0]);
     /*** get the number of unique chars ***/
     $chars = str_split($password);
     $num_unique_chars = sizeof(array_unique($chars));
     $strength += $num_unique_chars * 2;
     /*** strength is a number 1-10; ***/
     $strength = $strength > 99 ? 99 : $strength;
     $strength = floor($strength / 10 + 1);
     $min_strength = \Phalcon\DI::getDefault()->getShared('config')->auth->password_strength;
     if ($error || $strength < $min_strength) {
         $message = $this->getOption("message");
         if (empty($message)) {
             if ($error) {
                 $message = 'Please enter a passsword!';
             } else {
                 $message = 'Weak password! Try longer with mix of upper & lower case and numbers';
             }
         }
         $validation->appendMessage(new \Phalcon\Validation\Message($message, $field, "Password"));
         return false;
     }
     return TRUE;
 }
开发者ID:al35mm,项目名称:Phalcon-Rocket,代码行数:58,代码来源:Password.php

示例10: validate

 public function validate(\Phalcon\Validation $validator, $attribute)
 {
     $value = $validator->getValue($attribute);
     if (isset($value['error']) and isset($value['name']) and isset($value['type']) and isset($value['tmp_name']) and isset($value['size'])) {
         return true;
     }
     $validator->appendMessage(new Message('Некорректный файл.', $attribute, 'upload_valid'));
     return false;
 }
开发者ID:atnartur,项目名称:SimpleBannerRotator,代码行数:9,代码来源:UploadValid.php

示例11: validate

 public function validate(Validation $validator, $attribute)
 {
     $value = $validator->getValue($attribute);
     if (preg_match('/^[a-zA-Z\\x{4e00}-\\x{9fa5}][a-zA-Z\\x{4e00}-\\x{9fa5}_ ]{1,19}$/u', $value) == 0) {
         $validator->appendMessage(new Message('您填写的动物名格式有误,动物名只能包含2-20个英文大小写字母、汉字、数字、下划线和空格,且不能以数字、下划线和空格开头', $attribute));
         return false;
     }
     return true;
 }
开发者ID:sieg1980,项目名称:pohome,代码行数:9,代码来源:Petname.php

示例12: validate

 public function validate(Validation $validator, $attribute)
 {
     $value = $validator->getValue($attribute);
     $time = strtotime($value);
     $message = $this->getOption('message');
     if (!$message) {
         $message = '您填写的时间日期格式有误';
     }
     if ($time == false) {
         $validator->appendMessage(new Message($message, $attribute));
         return false;
     }
     if (date('Y-n-j H:i:s', $time) != $value) {
         $validator->appendMessage(new Message($message, $attribute));
         return false;
     }
     return true;
 }
开发者ID:sieg1980,项目名称:pohome,代码行数:18,代码来源:Datetime.php

示例13: validate

 public function validate(\Phalcon\Validation $validator, $attribute)
 {
     $user = new \Models\User();
     if (!$user->isAuth($validator->getValue('login'), $validator->getValue($attribute))) {
         $validator->appendMessage(new \Phalcon\Validation\Message($this->getOption('message'), $attribute));
         return false;
     }
     return true;
 }
开发者ID:xsat,项目名称:www.test.com,代码行数:9,代码来源:Auth.php

示例14: validate

 public function validate(\Phalcon\Validation $validator, $attribute)
 {
     $value = $validator->getValue($attribute);
     if ((bool) getimagesize($value['tmp_name'])) {
         return true;
     } else {
         $validator->appendMessage(new Message('Файл не является изображением. Для загрузки разрешены только изображения.', $attribute, 'upload_image'));
         return false;
     }
 }
开发者ID:atnartur,项目名称:SimpleBannerRotator,代码行数:10,代码来源:UploadImage.php

示例15: validate

 /**
  * @see \Phalcon\Validation\Validator::validate
  * @param Validation $validator
  * @param $attribute
  * @return bool
  */
 public function validate(Validation $validator, $attribute)
 {
     $value = $validator->getValue($attribute);
     $result = call_user_func($this->_options['callback'], $value);
     if (!$result) {
         $message = isset($this->_options['message']) ? $this->_options['message'] : 'validation failed';
         $validator->appendMessage(new Message($message, $attribute, 'callback'));
     }
     return $result ? true : false;
 }
开发者ID:tomi20v,项目名称:phalswag,代码行数:16,代码来源:Callback.php


注:本文中的Phalcon\Validation::appendMessage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。