Class: ActiveModel::Validations::BicValidator

Inherits:
EachValidator
  • Object
show all
Defined in:
lib/active_model/validations/bic_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



11
12
13
14
15
16
# File 'lib/active_model/validations/bic_validator.rb', line 11

def validate_each(record, attribute, value)
  country_field = options[:country] ? record[options[:country]] : "[A-Z]{2}"
  unless /[A-Z]{4}#{country_field}[0-9A-Z]{2,5}/.match? value.upcase
    record.errors.add(attribute, :invalid_format)
  end
end