Class: SEPA::IBANValidator

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

Constant Summary collapse

REGEX =

IBAN2007Identifier (taken from schema)

/\A[A-Z]{2,2}[0-9]{2,2}[a-zA-Z0-9]{1,30}\z/

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object


7
8
9
10
11
12
13
14
# File 'lib/sepa_king/validator.rb', line 7

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

  unless IBANTools::IBAN.valid?(value) && value.match?(REGEX)
    record.errors.add(field_name, :invalid, message: options[:message])
  end
end