Class: SEPA::BICValidator

Inherits:
ActiveModel::Validator
  • Object
show all
Defined in:
lib/sepa_king/validator.rb

Constant Summary collapse

REGEX =

AnyBICIdentifier (taken from schema)

/\A[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}\z/.freeze

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



20
21
22
23
24
25
# File 'lib/sepa_king/validator.rb', line 20

def validate(record)
  field_name = options[:field_name] || :bic
  value = record.send(field_name)

  record.errors.add(field_name, :invalid, message: options[:message]) if value && !value.to_s.match(REGEX)
end