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(); }
/** * @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; } } } } }
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(); }
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(); }
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)); }
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; }
/** * 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(); }