/** * Validate a string as fitting the unique name pattern * * This function is similar to @reason_unique_name_valid_string(), but returns the given string if the given string matches the pattern * * @param string $string The string to validate * @return string The given string if it matches the pattern; otherwise an empty string */ function reason_unique_name_validate_string($string) { if (reason_unique_name_valid_string($string)) { return $string; } return ''; }
function _check_unique_name_field() { if ($this->get_value('unique_name')) { if (!reason_unique_name_valid_string($this->get_value('unique_name'))) { $this->set_error('unique_name', 'Unique name must be just numbers, letters, and/or underscores. Please make sure the unique name doesn\'t contain any other characters.'); } else { $id = id_of($this->get_value('unique_name'), true, false); if (!empty($id) && $id != $this->_id) { $entity = new entity($id); $this->set_error('unique_name', 'The unique name "' . $this->get_value('unique_name') . '" is already used by the item "' . $entity->get_value('name') . '". Please choose another.'); } } } }