logo
VitNX3 Documentation

# Text.IsValidCardNumber Method

Namespace: VitNX3.Functions.Data
Assembly: VitNX3 (in VitNX3.dll)
Are the valid card number.
VB
C#
F#
C++
JScript
Copy

    public static bool IsValidCardNumber(
       string cardNumber
    )

    This language is not supported or no code example is available.

#### Parameters

cardNumber
  string

The card number.

#### Return Value

bool

A bool.

Source code
VB
C#
F#
C++
JScript
Copy

    public static bool IsValidCardNumber(string cardNumber)
     {
         cardNumber = cardNumber.Replace(" ", "");
         int[] doubledDigits = new int[cardNumber.Length / 2];
         int k = 0;
         for (int i = cardNumber.Length - 2; i >= 0; i -= 2)
         {
             int digit = int.Parse(cardNumber[i].ToString());
             doubledDigits[k] = digit * 2;
             k++;
         }
         int total = 0;
         foreach (int i in doubledDigits)
         {
             string number = i.ToString();
             for (int j = 0; j < number.Length; j++)
                 total += int.Parse(number[j].ToString());
         }
         int total2 = 0;
         for (int i = cardNumber.Length - 1; i >= 0; i -= 2)
         {
             int digit = int.Parse(cardNumber[i].ToString());
             total2 += digit;
         }
         int final = total + total2;
         return final % 10 == 0;
     }

    This language is not supported or no code example is available.

Applies to

#### .NET Framework

Supported in: 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8

#### .NET Core

Supported in: 5.0+, 6.0+
See Also
Text Class
VitNX3.Functions.Data Namespace