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


PHP Field::validate方法代码示例

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


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

示例1: validate

 function validate()
 {
     $errors = parent::validate();
     $validator = new Validator($this->_value);
     if ($this->_max_length > -1) {
         $validator->maxLength($this->_max_length, sprintf("%s must not exceed %d characters", $this->getName(), $this->_max_length));
     }
     $this->_errors = array_merge($errors, $validator->allErrors());
     return $this->allErrors();
 }
开发者ID:etenil,项目名称:assegai,代码行数:10,代码来源:SizedField.php

示例2: validate

 /**
  * @todo rewrite this whole validation
  * @see lib/fapi/Forms/Field#validate()
  */
 public function validate()
 {
     //Perform validation on the parent class.
     if (!parent::validate()) {
         return false;
     }
     if ($this->getValue() == "") {
         return true;
     }
     //Perform validation on text fields
     if ($this->type == "TEXT") {
         if (!is_numeric($this->getValue())) {
             if ($this->max_lenght > 0 && strlen($this->getValue()) > $this->max_lenght) {
                 $this->error = true;
                 array_push($this->errors, "The lenght of the text in this field cannot exceed {$this->max_lenght}");
                 return false;
             }
         }
         return true;
     } else {
         if ($this->type == "NUMERIC") {
             if (is_numeric($this->getValue())) {
                 if ($this->min_val != $this->max_val) {
                     if (!($this->getValue() >= (string) $this->min_val && $this->getValue() <= (string) $this->max_val)) {
                         $this->error = true;
                         array_push($this->errors, "The value of the number in this field must be between {$this->min_val} and {$this->max_val}");
                         return false;
                     }
                 }
             } else {
                 $this->error = true;
                 array_push($this->errors, "The value of this field is expected to be a number.");
                 return false;
             }
             return true;
         } else {
             if ($this->type == "REGEXP") {
                 if (preg_match($this->regexp, $this->getValue()) == 1) {
                     return true;
                 } else {
                     array_push($this->errors, "The format of this field is invalid");
                     $this->error = true;
                     return false;
                 }
             }
         }
     }
 }
开发者ID:ekowabaka,项目名称:wyf,代码行数:52,代码来源:TextField.php

示例3: validate

 function validate()
 {
     $errors = parent::validate();
     $validator = new Validator($this->_value);
     $validator->date(sprintf("%s is not a date", $this->getName()));
     if ($this->_min_value) {
         $validator->minDate(sprintf("%s is too small", $this->getName()));
     }
     if ($this->_max_value) {
         $validator->maxDate(sprintf("%s is too big", $this->getName()));
     }
     if ($validator->hasErrors()) {
         $this->_errors = array_merge($errors, $validator->allErrors());
     }
     return $this->allErrors();
 }
开发者ID:etenil,项目名称:assegai,代码行数:16,代码来源:DateField.php

示例4: validate

 function validate()
 {
     $errors = parent::validate();
     $validator = new Validator($this->_value);
     if (is_array($data) && !$this->isMultiple()) {
         $errors[] = sprintf("only choose one value for %s", $this->getName());
     } elseif (is_array($data) && $this->isMultiple()) {
         foreach ($data as $item) {
             $validator->setValue($item);
             $validator->oneOf($this->getChoices(), sprintf("'%s' is an unknown choice for %s", $item, $this->getName()));
         }
     } else {
         $validator->oneOf($this->getChoices(), sprintf("'%s' is an unknown choice for %s", $item, $this->getName()));
     }
     if ($validator->hasErrors()) {
         $this->_errors = array_merge($errors, $validator->allErrors());
     }
     return $this->allErrors();
 }
开发者ID:etenil,项目名称:assegai,代码行数:19,代码来源:RadioField.php

示例5: validate

	public function validate()
	{
		if ( !parent::validate() )
			return false;

		# NOTE: This does NOT check to see that the domain is valid, or that the email address can receive emails.
		# Got parts of this from http://phpsec.org/projects/guide/1.html#1.4.3 (CMB 2007-07-12)
		# Got list of disallowed punctuation and control characters from http://tfletcher.com/lib/rfc822.rb (CMB 2007-07-12)
		$regex = '/^
					[^\s@\x00-\x20"(),:;<>\x5b-\x5d\x7f-\xff]+	# at least 1 character: no spaces, @-signs, control-characters, most punctuation (including [\]), or non-ASCII characters
					@					# require the @ sign
					([-a-z0-9]+\.)+		# domain name must consist of alpha-numeric characters, dots, and dashes
					[a-z]{2,6}			# top-level domain must consist of at least 2 characters, and no more than 6 (museum and travel TLDs)
				$/xi';					# x = allow extended syntax, i = case insensitive
		return preg_match($regex, trim($this->value));
	}
开发者ID:boochtek,项目名称:php-base,代码行数:16,代码来源:form.php

示例6: validate

 public function validate()
 {
     parent::validate();
     if (!filter_var($this->getValue(), FILTER_VALIDATE_EMAIL)) {
         $this->valid = false;
         $this->errors['invalid'] = 'That is not a valid email address!';
     }
     if ($this->valid === false) {
         return false;
     }
     $this->valid = true;
     return true;
 }
开发者ID:plasticine,项目名称:rivet,代码行数:13,代码来源:Form.php

示例7: validate

 /**
  * Validates field's errors and returns them as array
  * @return array
  */
 public function validate()
 {
     if (is_null($this->decimals)) {
         $this->_addError("required option decimal_places was not set");
     }
     if (is_null($this->digits)) {
         $this->_addError("required option max_digits was not set");
     }
     if (!is_null($this->decimals) and !is_null($this->digits) and $this->digits < $this->decimals) {
         $this->_addError("max_digits has to be egual or bigger than decimal_places");
     }
     return parent::validate();
 }
开发者ID:Edke,项目名称:PerfORM,代码行数:17,代码来源:DecimalField.php


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