Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def luhn_valid?(value)
- return false unless value.is_a?(String) && !value.strip.empty?
- value.gsub!(/\D/, '')
- sum = 0
- value.split(//).each_with_index do |number, index|
- if index.even?
- sum += (number * 2).to_s.split(//).map(&:to_i).sum
- else
- sum += number
- end
- end
- sum % 10 == 0
- end
Add Comment
Please, Sign In to add comment