This is a mirror of official site: http://jasper-net.blogspot.com/

Credit Card Validation Check by Code

| Monday, June 14, 2010
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

Posted via email from .NET Info

0 comments: