Sha256: 470e8d9947ace61b6997dba13f632d2ddf008a5bd69adc1b0fce9e5798552a3d
Contents?: true
Size: 638 Bytes
Versions: 1
Compression:
Stored size: 638 Bytes
Contents
require "vailid/version" module Vailid LENGTH = 9 # Accepted maximal valid length for IL id number def self.valid?(*args) if (args.length == 1) validator(args.first) else false end end def self.validator(str) return false unless (str != nil) str=str.to_s return false unless (str.length <= LENGTH) return false unless (str.to_i != 0) while(str.length < LENGTH) str="0".concat(str) end sum=0 for i in 0..(LENGTH-1) if (i%2==0) sum+= str[i].to_i else temp= 2*str[i].to_i (temp=temp/10 + temp%10) unless (temp<10) sum+=temp end end (sum%10==0)? true : false end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
vailid-1.0.2 | lib/vailid.rb |