diff --git a/app/models/nameserver.rb b/app/models/nameserver.rb index f95e56f07..1afc67a8d 100644 --- a/app/models/nameserver.rb +++ b/app/models/nameserver.rb @@ -2,6 +2,6 @@ class Nameserver < ActiveRecord::Base belongs_to :registrar has_and_belongs_to_many :domains - validates :hostname, hostname: true - validates :ip, format: { with: /\A(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\z/, allow_nil: true, message: :ip_invalid} + validates :hostname, format: { with: /\A(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/ } + validates :ip, format: { with: /\A(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\z/, allow_nil: true } end diff --git a/app/validators/hostname_validator.rb b/app/validators/hostname_validator.rb deleted file mode 100644 index cb9bbdfef..000000000 --- a/app/validators/hostname_validator.rb +++ /dev/null @@ -1,13 +0,0 @@ -class HostnameValidator < ActiveModel::EachValidator - def validate_each(record, attribute, value) - if !self.class.validate_format(value) - record.errors.add(attribute, (options[:message] || :invalid)) - end - end - - class << self - def validate_format(value) - !!(value =~ /\A(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/) - end - end -end diff --git a/app/validators/nameserver_ip_validator.rb b/app/validators/nameserver_ip_validator.rb deleted file mode 100644 index 2816b1b0e..000000000 --- a/app/validators/nameserver_ip_validator.rb +++ /dev/null @@ -1,15 +0,0 @@ -class NameserverIpValidator < ActiveModel::EachValidator - def validate_each(record, attribute, value) - if record.domain_ - - if !self.class.validate_format(value) - record.errors.add(attribute, (options[:message] || :invalid)) - end - end - - class << self - def validate_format(value) - !!(value =~ /\A(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])\z/) - end - end -end diff --git a/config/locales/en.yml b/config/locales/en.yml index 598cab91a..23088e67a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -55,7 +55,7 @@ en: hostname: invalid: 'Hostname is invalid' ip: - ip_invalid: 'IP is invalid' + invalid: 'IP is invalid' errors: