Skip to content
Snippets Groups Projects
Commit 175f482c authored by Robert Speicher's avatar Robert Speicher
Browse files

Add custom NamespaceNameValidator

parent 9321d382
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -23,10 +23,10 @@ class Namespace < ActiveRecord::Base
 
validates :owner, presence: true, unless: ->(n) { n.type == "Group" }
validates :name,
presence: true, uniqueness: true,
length: { within: 0..255 },
format: { with: Gitlab::Regex.namespace_name_regex,
message: Gitlab::Regex.namespace_name_regex_message }
namespace_name: true,
presence: true,
uniqueness: true
 
validates :description, length: { within: 0..255 }
validates :path,
Loading
Loading
# NamespaceNameValidator
#
# Custom validator for GitLab namespace name strings.
class NamespaceNameValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless value =~ Gitlab::Regex.namespace_name_regex
record.errors.add(attribute, Gitlab::Regex.namespace_name_regex_message)
end
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment