Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# https://stackoverflow.com/a/29299786/512507
def self.valid_id?(id)
case id
when /^[a-zA-Z0-9]{15}$/
return true
when /^[a-zA-Z0-9]{18}$/
id[15..17] == [
id[0..4],
id[5..9],
id[10..14]
].map(&:reverse).
map do |p|
(('A'..'Z').to_a + ('0'..'9').to_a)[
p.chars.map { |c| c =~ /[A-Z]/ ? '1' : '0' }.join.to_i(2)
]
end.join
else
return false
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.