Skip to content

Instantly share code, notes, and snippets.

@skanev
Created August 28, 2009 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skanev/177007 to your computer and use it in GitHub Desktop.
Save skanev/177007 to your computer and use it in GitHub Desktop.
def egn_valid?
egn =~ /^(\d{2})(\d{2})(\d{2})\d{3}(\d)$/ and
egn.each_char[0...9].zip([2, 4, 8, 5, 10, 9, 7, 3, 6]).sum { |d, w| d.to_i * w } % 11 % 10 == $4.to_i and
Date.valid_civil?($1.to_i, $2.to_i % 20, $3.to_i) and
$2.to_i / 20 <= 2
end
# Алгоритъм от тук: http://www.grao.bg/esgraon.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment