mirror of
https://github.com/internetee/registry.git
synced 2025-08-01 07:26:22 +02:00
parent
834b13c922
commit
7530dd7b62
4 changed files with 24 additions and 23 deletions
|
@ -1,19 +1,20 @@
|
|||
class Contact::Ident::CodeValidator < ActiveModel::EachValidator
|
||||
def validate_each(record, attribute, value)
|
||||
if record.country_code == 'EE'
|
||||
if record.national_id?
|
||||
record.errors.add(attribute,
|
||||
:invalid_national_id,
|
||||
country: record.country) unless valid_national_id_ee?(value)
|
||||
end
|
||||
return unless record.country_code == 'EE'
|
||||
|
||||
if record.reg_no?
|
||||
validator = ActiveModel::Validations::FormatValidator.new(with: reg_no_ee_format,
|
||||
attributes: attribute,
|
||||
message: :invalid_reg_no,
|
||||
country: record.country)
|
||||
validator.validate(record)
|
||||
end
|
||||
if record.national_id? && !valid_national_id_ee?(value)
|
||||
record.errors.add(attribute,
|
||||
:invalid_national_id,
|
||||
country: record.country)
|
||||
end
|
||||
|
||||
if record.reg_no?
|
||||
validator = ActiveModel::Validations::
|
||||
FormatValidator.new(with: reg_no_ee_format,
|
||||
attributes: attribute,
|
||||
message: :invalid_reg_no,
|
||||
country: record.country)
|
||||
validator.validate(record)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue