12,952,124 members (57,852 online)
alternative version

#### Stats

70.2K views
28 bookmarked
Posted 18 Jun 2005

# How To Validate Credit Card Numbers

, 23 May 2006
 Rate this:
Beginners

## ExampleConsider the example identification number 456-565-654. The first step is to double every other digit, starting with the second-to-last digit and moving left, and sum the digits in the result. The following table shows this step (highlighted rows indicating doubled digits):Digit Doubled Sum of digits <o:p>

4 4 4  <o:p>

5 10 1 <o:p>

6 6 6 <o:p>

5 10 1 <o:p>

6 6 6 <o:p>

5 10 1 <o:p>

6 6 6 <o:p>

5 10 1 <o:p>

4 4 4 <o:p>

Sum: 30 <o:p>

<o:p>

The sum of 30 is divided by 10; the remainder is 0, so the number is valid.<o:p>

## Code <o:p>

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim sum As Int32 = 0 Dim cdigit As Char Dim i, digit As Int32 Dim nDigit As Int32 Dim parity As Int32 nDigit = TextBox1.TextLength parity = nDigit Mod 2 For i = 0 To nDigit - 1 cdigit = TextBox1.Text.Chars(i) digit = cdigit.GetNumericValue(cdigit) If i Mod 2 = parity Then digit = digit * 2 End If If digit > 9 Then digit = digit - 9 End If sum = sum + digit Next If sum Mod 10 = 0 Then MsgBox("Approved") Else MsgBox("Not Approved") End If End Sub

## Conclusion

I think it is very useful for those who are in learning process and want to  learn and try different things.

A list of licenses authors might use can be found here

## Share

 Web Developer Other
No Biography provided

## You may also be interested in...

 Pro

 First Prev Next
 My vote of 1 Obaid ur Rehman21-Mar-13 1:38 Obaid ur Rehman 21-Mar-13 1:38
 My vote of 5 Heaven20203-Nov-10 7:00 Heaven2020 3-Nov-10 7:00