(adsbygoogle = window.adsbygoogle || []).push({});*** THIS WILL ONLY WORK IF THE USER IS CONNECTED TO THE INTERNET ***
Introduction:
Hey guys, this is the fourth tutorial in the VB programming series. Once again, I have checked and I believe there is no other threads on how to do this.
Tutorial: #4 - Credit Card Validation
Required Materials:
~ VB 2010 or 2008
Features:
We will be making a basic form that will have a masked textbox, that the user will enter their credit card number in, and will be validated through official servers to check if the card is valid. THIS IS NOT A CC DETAIL STEALER!! THIS VERIFIES THROUGH OFFICIAL SERVERS. You might want to let your user know this as well for security reasons.
Video:
How to do it:
First we are going to create a new WindowsFormApplication, or open an already created one. I am naming mine NGU CC Validator.
Now we are going to add 2 objects, 4 textboxes, and a button. You can place them wherever you want, it doesn't matter. Your form should look something similar to this:
Now to the coding! We first need to create a private function to check if the credit card number entered is legit or not. We will call this function "ccchecker".
Private Function ccchecker(ByVal value As String) As Boolean
Dim checksum As Integer = 0
Dim doubleflag As Boolean = (value.Length Mod 2 = 0)
Dim ccnumber As Char
Dim ccnumbervalue As Integer
For Each ccnumber In value
ccnumbervalue = Integer.Parse(ccnumber)
If doubleflag Then
ccnumbervalue *= 2
If ccnumbervalue > 9 Then
ccnumbervalue -= 9
End If
End If
checksum += ccnumbervalue
doubleflag = Not doubleflag
Next
Return (checksum Mod 10 = 0)
End Function
Now we must link the button to check this function with the number provided. This is fairly simple to do, as you will see.
If ccchecker(TextBox1.Text & TextBox2.Text & TextBox3.Text & TextBox4.Text) Then
MsgBox("This card has been validated as a correct card number!", MsgBoxStyle.Information)
Else
MsgBox("This card has been validated as an incorrect card number", MsgBoxStyle.Critical)
End If
We are done! If you enter an incorrect card number, you should see a popup like this: