demarches-normaliennes/app/validators/iban_validator.rb
2020-09-23 15:56:26 +02:00

11 lines
279 B
Ruby

require 'iban-tools'
class IbanValidator < ActiveModel::Validator
def validate(record)
if record.value.present?
unless IBANTools::IBAN.valid?(record.value)
record.errors.add :iban, record.errors.generate_message(:value, :invalid)
end
end
end
end