mirror of
https://github.com/internetee/registry.git
synced 2025-07-24 11:38:30 +02:00
Domain name validator
This commit is contained in:
parent
8f131c2fe4
commit
b670331b1a
4 changed files with 25 additions and 0 deletions
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