Skip to content

Instantly share code, notes, and snippets.

@georgespingos
Created December 13, 2012 11:30
Show Gist options
  • Save georgespingos/4275860 to your computer and use it in GitHub Desktop.
Save georgespingos/4275860 to your computer and use it in GitHub Desktop.
C# Validate AMKA
public static bool ValidateAMKA(string AMKA)
{
double _numAMKA = 0;
int sum = int.Parse(AMKA.Last().ToString());
if (AMKA.Length != 11 || !double.TryParse(AMKA, out _numAMKA))
return false;
else
{
int iter = AMKA.Length - 1;
AMKA.ToCharArray().Take(iter).ToList().ForEach(c =>
{
if (iter % 2 != 0)
{
int DigitTimes2 = int.Parse(c.ToString()) * 2;
if (DigitTimes2 > 9)
sum += 1 + DigitTimes2 % 10;
else
sum += DigitTimes2;
}
else
sum += int.Parse(c.ToString());
iter--;
});
}
if (sum % 10 == 0)
return true;
else
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment