Domain name validator

This commit is contained in:
Martin Lensment 2014-06-30 13:40:58 +03:00
parent 8f131c2fe4
commit b670331b1a
4 changed files with 25 additions and 0 deletions

View 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