Created
December 13, 2012 11:30
-
-
Save georgespingos/4275860 to your computer and use it in GitHub Desktop.
C# Validate AMKA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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