value)) { if (!is_null($min) && ($this->value < $min)) { // below min $this->errors['numrange'] = true; $this->error_messages['numrange'] = t('Value is below minimum of').' '.$min; } elseif (!is_null($max) && ($this->value > $max)) { // above max $this->errors['numrange'] = true; $this->error_messages['numrange'] = t('Value is above maximum of').' '.$max;; } } else { // not numeric $this->errors['numrange'] = true; $this->error_messages['numrange'] = t('Value is not numeric'); } } /** * Custom validation rule: color * returns no error if string is formatted as #hhhhhh OR if string is empty * to exclude the empty case, add "required" as another rule */ protected function rule_color() { if (preg_match("/^#[0-9A-Fa-f]{6}$|^$/", $this->value) == 0) { $this->errors['color'] = true; $this->error_messages['color'] = t('Color is not in #hhhhhh format'); } } }