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/

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



21
22
23
24
25
26
27
28
29
30
# File 'lib/sepa_king/validator.rb', line 21

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

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