Class: Ea::Validation::CompaniesHouseNumberValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/ea/validation/companies_house_number_validator.rb

Constant Summary collapse

VALID_COMPANIES_HOUSE_REGISTRATION_NUMBER_REGEX =
Regexp.new(/\A(\d{8,8}$)|([a-zA-Z]{2}\d{6}$)\z/i).freeze

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/ea/validation/companies_house_number_validator.rb', line 18

def validate_each(record, attribute, value)
  value.strip!
  unless value =~ VALID_COMPANIES_HOUSE_REGISTRATION_NUMBER_REGEX
    record.errors.add(
      attribute,
      (options[:message] || I18n.t("ea.validation.errors.companies_house_number.#{attribute}.invalid_html"))
    )
  end
end