2020-09-22 16:04:57 +02:00
|
|
|
require 'iban-tools'
|
|
|
|
|
|
|
|
class IbanValidator < ActiveModel::Validator
|
|
|
|
def validate(record)
|
|
|
|
if record.value.present?
|
|
|
|
unless IBANTools::IBAN.valid?(record.value)
|
2023-04-28 15:32:34 +02:00
|
|
|
record.errors.add :value, message: record.errors.generate_message(:value, :invalid_iban)
|
2020-09-22 16:04:57 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|