class SEPA::CreditorIdentifierValidator

Constants

REGEX

Public Instance Methods

valid?(creditor_identifier) click to toggle source
# File lib/sepa_king/validator.rb, line 38
def valid?(creditor_identifier)
  if ok = creditor_identifier.to_s.match(REGEX) && creditor_identifier[0..1].match(/DE/i)
    # In Germany, the identifier has to be exactly 18 chars long
    ok = creditor_identifier.length == 18
  end
  ok
end
validate(record) click to toggle source
# File lib/sepa_king/validator.rb, line 31
def validate(record)
  field_name = options[:field_name] || :creditor_identifier
  value = record.send(field_name)

  record.errors.add(field_name, :invalid, message: options[:message]) unless valid?(value)
end