mirror of
https://github.com/internetee/registry.git
synced 2025-07-21 10:16:01 +02:00
14 lines
408 B
Ruby
14 lines
408 B
Ruby
class DomainNameValidator < ActiveModel::EachValidator
|
|
def validate_each(record, attribute, value)
|
|
unless self.class.validate(value)
|
|
record.errors[attribute] << (options[:message] || 'invalid format')
|
|
end
|
|
end
|
|
|
|
class << self
|
|
def validate(value)
|
|
ok = value =~ /\A[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]\.ee\z/
|
|
ok &&= !(value[2] == '-' && value[3] == '-')
|
|
end
|
|
end
|
|
end
|