mirror of
https://github.com/internetee/registry.git
synced 2025-08-03 00:12:03 +02:00
Domain name validator
This commit is contained in:
parent
8f131c2fe4
commit
b670331b1a
4 changed files with 25 additions and 0 deletions
|
@ -5,6 +5,8 @@ class Domain < ActiveRecord::Base
|
|||
belongs_to :technical_contact, class_name: 'Contact'
|
||||
belongs_to :admin_contact, class_name: 'Contact'
|
||||
|
||||
validates :name, domain_name: true
|
||||
|
||||
class << self
|
||||
def check_availability(domains)
|
||||
res = []
|
||||
|
|
10
app/validators/domain_name_validator.rb
Normal file
10
app/validators/domain_name_validator.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
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
|
||||
record.errors[attribute] << (options[:message] || 'invalid format')
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue