Sha256: 891cb3bc48e71c1bc913b2fe38049642c44647f2ae0de56f69560e8a783eec55
Contents?: true
Size: 735 Bytes
Versions: 16
Compression:
Stored size: 735 Bytes
Contents
class ZipValidator < ActiveModel::EachValidator def initialize(options = {}) super(options) @other = options[:other] end def validate_each(record, attribute, value) zip1 = value zip2 = get_other_value(record) return if (zip1.nil? or zip1.empty?) and (zip2.nil? or zip2.empty?) unless validate_zip(zip1, zip2) record.errors[attribute] << I18n.t('errors.messages.zip') return end end private def validate_zip(zip1, zip2) return false unless zip1 return false unless zip1.match(/^[0-9|0-9]{3}$/) return false unless zip2 return false unless zip2.match(/^[0-9|0-9]{4}$/) true end def get_other_value(record) record.__send__(@other) end end
Version data entries
16 entries across 16 versions & 1 rubygems