mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 18:56:05 +02:00
Handle children errors
This commit is contained in:
parent
3dca771bcb
commit
9ce6efc4db
8 changed files with 86 additions and 9 deletions
13
app/validators/hostname_validator.rb
Normal file
13
app/validators/hostname_validator.rb
Normal file
|
@ -0,0 +1,13 @@
|
|||
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
|
Loading…
Add table
Add a link
Reference in a new issue