Sha256: 0fda069262d22b561cae2ec8f57d0b64d1ef457cb8cee85242059c63b24ef50d
Contents?: true
Size: 480 Bytes
Versions: 2
Compression:
Stored size: 480 Bytes
Contents
# frozen_string_literal: true class ImeiValidator < BaseValidator REGEXP = /\A[\d.:\-\s]+\z/i.freeze private def valid_attr? valid_regexp? && valid_checksum? end def valid_checksum? number = value.to_s.gsub(/\D/, '').reverse total = 0 number.chars.each_with_index do |chr, idx| result = chr.to_i result *= 2 if idx.odd? result = (1 + (result - 10)) if result >= 10 total += result end (total % 10).zero? end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
lite-validators-1.2.0 | lib/lite/validators/imei_validator.rb |
lite-validators-1.1.2 | lib/lite/validators/imei_validator.rb |