mirror of
https://github.com/internetee/registry.git
synced 2025-05-28 13:51:41 +02:00
Domain name validation
This commit is contained in:
parent
35155fb8ac
commit
c5355ca8f5
2 changed files with 9 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
|||
class DomainNameValidator < ActiveModel::EachValidator
|
||||
#TODO
|
||||
#TODO
|
||||
# validates lenght of 2-63
|
||||
# validates/honours Estonian additional letters zäõüö
|
||||
# honours punicode and all interfces honors utf8
|
||||
|
@ -14,7 +14,12 @@ class DomainNameValidator < ActiveModel::EachValidator
|
|||
|
||||
class << self
|
||||
def validate(value)
|
||||
ok = value =~ /\A[a-zA-Z0-9][a-zA-Z0-9-]{0,61}[a-zA-Z0-9]\.ee\z/
|
||||
value = value.mb_chars.downcase.strip
|
||||
|
||||
general_domains = /(.pri.ee|.edu.ee|.aip.ee|.org.ee|.med.ee|.riik.ee|.ee)/ #TODO Add more general domains here
|
||||
unicode_chars = /\u00E4\u00F5\u00F6\u00FC\u0161\u017E/ #äõöüšž
|
||||
ok = value =~ /\A[a-zA-Z0-9#{unicode_chars}][a-zA-Z0-9#{unicode_chars}-]{0,61}[a-zA-Z0-9#{unicode_chars}]#{general_domains}\z/
|
||||
|
||||
ok &&= !(value[2] == '-' && value[3] == '-')
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue