Sha256: 6e1e2c5d7e5670ec534829401f6af2465c8130f335e564497d4a0ede45f3192c
Contents?: true
Size: 770 Bytes
Versions: 7
Compression:
Stored size: 770 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
7 entries across 7 versions & 1 rubygems