Sha256: d47928ca0985df394e4eb4017831218bb5741019059fc4d2ed046f7998807cf8
Contents?: true
Size: 1.72 KB
Versions: 3
Compression:
Stored size: 1.72 KB
Contents
# encoding: utf-8 module SEPA class IBANValidator < ActiveModel::Validator def validate(record) field_name = options[:field_name] || :iban value = record.send(field_name) unless IBANTools::IBAN.valid?(value.to_s) record.errors.add(field_name, :invalid) end end end class BICValidator < ActiveModel::Validator REGEX = /\A[A-Z]{6,6}[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3,3}){0,1}\z/ 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) end end end end class CreditorIdentifierValidator < ActiveModel::Validator REGEX = /\A[a-zA-Z]{2,2}[0-9]{2,2}([A-Za-z0-9]|[\+|\?|\/|\-|\:|\(|\)|\.|,|']){3,3}([A-Za-z0-9]|[\+|\?|\/|\-|:|\(|\)|\.|,|']){1,28}\z/ def validate(record) field_name = options[:field_name] || :creditor_identifier value = record.send(field_name) unless valid?(value) record.errors.add(field_name, :invalid) end end def valid?(creditor_identifier) if ok = creditor_identifier.to_s.match(REGEX) # In Germany, the identifier has to be exactly 18 chars long if creditor_identifier[0..1].match(/DE/i) ok = creditor_identifier.length == 18 end end ok end end class MandateIdentifierValidator < ActiveModel::Validator REGEX = /\A([A-Za-z0-9]|[\+|\?|\/|\-|\:|\(|\)|\.|\,|\']){1,35}\z/ def validate(record) field_name = options[:field_name] || :mandate_id value = record.send(field_name) unless value.to_s.match(REGEX) record.errors.add(field_name, :invalid) end end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
sepa_king-0.4.0 | lib/sepa_king/validator.rb |
sepa_king-0.3.0 | lib/sepa_king/validator.rb |
sepa_king-0.2.0 | lib/sepa_king/validator.rb |