private bool CheckIsValidCreditCard(string CreditCard)
{
bool IsValidCreditCard = false; int sum = 0;
int MultiplyDigit = 0;
for (int i = 0; i < CreditCard.Length; i++)
{
if (i % 2 == 0)
{
MultiplyDigit =
Convert.ToInt32(CreditCard.Substring(i, 1)) * 2;
if (MultiplyDigit > 9)
sum += MultiplyDigit - 9;
else
sum += MultiplyDigit;
}
else
sum += Convert.ToInt32(CreditCard.Substring(i, 1));
}
if (sum % 10 == 0)
IsValidCreditCard = true; return IsValidCreditCard;
}Read more: Dudi Nissan's Blog
Read more: Anatomy of Credit Card Numbers
{
bool IsValidCreditCard = false; int sum = 0;
int MultiplyDigit = 0;
for (int i = 0; i < CreditCard.Length; i++)
{
if (i % 2 == 0)
{
MultiplyDigit =
Convert.ToInt32(CreditCard.Substring(i, 1)) * 2;
if (MultiplyDigit > 9)
sum += MultiplyDigit - 9;
else
sum += MultiplyDigit;
}
else
sum += Convert.ToInt32(CreditCard.Substring(i, 1));
}
if (sum % 10 == 0)
IsValidCreditCard = true; return IsValidCreditCard;
}Read more: Dudi Nissan's Blog
Read more: Anatomy of Credit Card Numbers
0 comments:
Post a Comment