Class: SEPA::MandateIdentifierValidator

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

Constant Summary collapse

REGEX =
%r{\A([A-Za-z0-9]|[+|?|/|\-|:|(|)|.|,|']){1,35}\z}.freeze

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



50
51
52
53
54
55
# File 'lib/sepa_king/validator.rb', line 50

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

  record.errors.add(field_name, :invalid, message: options[:message]) unless value.to_s.match(REGEX)
end