demarches-normaliennes/app/validators/iban_validator.rb

12 lines
294 B
Ruby
Raw Normal View History

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)
record.errors.add :value, message: record.errors.generate_message(:value, :invalid_iban)
2020-09-22 16:04:57 +02:00
end
end
end
end