Sha256: 639b04d15e9de5f51c5a9ce2aae2be5ce5bcec6d942ba16a0ec500976b6cc175
Contents?: true
Size: 519 Bytes
Versions: 15
Compression:
Stored size: 519 Bytes
Contents
class Unidom::Certificate::China::IdentificationNumberValidator < ActiveModel::EachValidator WEIGHTS = [ 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2 ].freeze CHECK_DIGITS = %w{1 0 X 9 8 7 6 5 4 3 2}.freeze def validate_each(record, attribute, value) value = value.to_s sum = 0 value[0..16].chars.each_with_index do |char, index| sum += char.to_i*WEIGHTS[index] end record.errors[attribute] << (options[:message]||'is invalid') unless CHECK_DIGITS[sum%11]==value[17] end end
Version data entries
15 entries across 15 versions & 1 rubygems