Post: VB.NET Programming Tutorial - CC VALIDATION
03-27-2013, 08:44 PM #1
Specter
Pro Memer
(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.

You must login or register to view this content.

Now once you have done this, you may customize the form and such. You should see something similar to this on your screen:

You must login or register to view this content.

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:

You must login or register to view this content.

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".

You must login or register to view this content.

Code to Copy:
    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.

You must login or register to view this content.

Code To Copy:
    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:

You must login or register to view this content.

If you enter a correct card number, you should see a popup like this:

You must login or register to view this content.

Have a good Wednesday NGU.
Last edited by Specter ; 03-28-2013 at 10:20 PM.
03-28-2013, 09:43 PM #2
im using this at the moment thanks

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo