本文整理汇总了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();
}
示例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;
}
}
}
}
}
示例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();
}
示例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();
}
示例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));
}
示例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;
}
示例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();
}