Class: SEPA::MandateIdentifierValidator

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

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#validate(record) ⇒ Object



59
60
61
62
63
64
65
66
# File 'lib/sepa_king/validator.rb', line 59

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, message: options[:message])
  end
end