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)
  return unless value.present?

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