public function validate($label, $value) { $parent_val = parent::validate($label, $value); if ($parent_val !== TRUE) { return $parent_val; } if (!$this->required && empty($value)) { return TRUE; } if (!is_email($value)) { return sprintf(__('%1$s is not a valid email address.', 'cuar'), $label); } return TRUE; }
public function validate($label, $value) { $parent_val = parent::validate($label, $value); if ($parent_val !== TRUE) { return $parent_val; } $errors = array(); if ($this->min_length != null && strlen($value) < $this->min_length) { $errors[] = sprintf(__('%1$s must contain at least %2$s characters', 'cuar'), $label, $this->min_length); } if ($this->max_length != null && strlen($value) > $this->max_length) { $errors[] = sprintf(__('%1$s must contain at most %2$s characters', 'cuar'), $label, $this->max_length); } return empty($errors) ? TRUE : $errors; }
public function validate($label, $value) { $parent_val = parent::validate($label, $value); if ($parent_val !== TRUE) { return $parent_val; } if (!is_numeric($value)) { return sprintf(__('%1$s is not a valid number', 'cuar'), $label); } if ($this->force_int && !is_int($value)) { return sprintf(__('%1$s is not a valid integer', 'cuar'), $label); } $errors = array(); if ($this->min != null && $value < $this->min) { $errors[] = sprintf(__('%1$s must be greater than %2$s', 'cuar'), $label, $this->min); } if ($this->max != null && $value > $this->max) { $errors[] = sprintf(__('%1$s must be lower than %2$s', 'cuar'), $label, $this->max); } return empty($errors) ? TRUE : $errors; }