12,349,363 members (66,088 online)
alternative version

67.5K views
28 bookmarked
Posted

# 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

4 4 4

5 10 1

6 6 6

5 10 1

6 6 6

5 10 1

6 6 6

5 10 1

4 4 4

Sum: 30

The sum of 30 is divided by 10; the remainder is 0, so the number is valid.

## Code

 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.

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

## About the Author

 Web Developer Other
No Biography provided

## Comments and Discussions

 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
 Not sure about your pseudo code. Ashaman22-Jun-05 2:10 Ashaman 22-Jun-05 2:10
 Last Visit: 31-Dec-99 18:00     Last Update: 25-Jun-16 1:34 Refresh 1

General    News    Suggestion    Question    Bug    Answer    Joke    Praise    Rant    Admin

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.