Domain name validation through EPP

This commit is contained in:
Martin Lensment 2014-06-30 14:16:58 +03:00
parent b592b973ff
commit d2e30c0c5f
3 changed files with 14 additions and 4 deletions

View file

@ -1,10 +1,14 @@
class DomainNameValidator < ActiveModel::EachValidator
def validate_each(record, attribute, 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] == '-')
unless ok
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