Determine Credit Card Type (Tutorial)
Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
3 posts
Page 1 of 1
For this tutorial, i'll show you how to create a program that determine the credit card type by entering the numbers of a credit card:
For this tutorial you need 2 TextBoxes and 1 Button
First we make sure that user enter numbers only in TextBox1
TextBox2.text will show the results:
Determine if the card is VISA:
'Determine if the card is American Express
'There are two options for Diners Cards: NOTE: YOU HAVE TO ENTER BOTH OPTIONS
'First:
Determine if card is DISCOVER
And now add the following code to the button click event:
visa()
For this tutorial you need 2 TextBoxes and 1 Button
First we make sure that user enter numbers only in TextBox1
Code: Select all
TextBox1.text will be used to enter the credit card numbersPrivate Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Asc(e.KeyChar) <> 13 AndAlso Asc(e.KeyChar) <> 8 _
AndAlso Not IsNumeric(e.KeyChar) Then
MessageBox.Show("Please Enter Numbers Only")
e.Handled = True
End If
End Sub
TextBox2.text will show the results:
Determine if the card is VISA:
Code: Select all
Public Sub visa()
TextBox1.SelectionStart = (0)
TextBox1.SelectionLength = (1)
If TextBox1.SelectedText = 4 And TextBox1.Text.Length = 16 Then
TextBox2.Text = " Visa Card"
Else
'If card is not a visa we check if it is a mastercard
mastercard()
End If
End Sub
Code: Select all
'----------------------------------------------------------------------------------------------------------------------Determine if the card is MasterCard:
Public Sub mastercard()
TextBox1.SelectionStart = (0)
TextBox1.SelectionLength = (2)
If TextBox1.SelectedText = 51 And TextBox1.Text.Length = 16 Then
TextBox2.Text = " MasterCard"
ElseIf TextBox1.SelectedText = 52 And TextBox1.Text.Length = 16 Then
TextBox2.Text = " MasterCard"
ElseIf TextBox1.SelectedText = 53 And TextBox1.Text.Length = 16 Then
TextBox2.Text = " MasterCard"
ElseIf TextBox1.SelectedText = 54 And TextBox1.Text.Length = 16 Then
TextBox2.Text = " MasterCard"
ElseIf TextBox1.SelectedText = 55 And TextBox1.Text.Length = 16 Then
TextBox2.Text = " MasterCard"
Else
'if card is not a MasterCard we Check if it is American Express
americanexpress()
End If
End Sub
'Determine if the card is American Express
Code: Select all
'---------------------------------------------------------------------------------------------------------------------------Public Sub americanexpress()
TextBox1.SelectionStart = (0)
TextBox1.SelectionLength = (2)
If TextBox1.SelectedText = 34 And TextBox1.Text.Length = 15 Then
TextBox2.Text = "American Express"
ElseIf TextBox1.SelectedText = 35 And TextBox1.Text.Length = 15 Then
TextBox2.Text = "American Express"
ElseIf TextBox1.SelectedText = 36 And TextBox1.Text.Length = 15 Then
TextBox2.Text = "American Express"
ElseIf TextBox1.SelectedText = 37 And TextBox1.Text.Length = 15 Then
TextBox2.Text = " American Express"
Else
diners1()
End If
End Sub
'There are two options for Diners Cards: NOTE: YOU HAVE TO ENTER BOTH OPTIONS
'First:
Code: Select all
'Second Option
Public Sub diners1()
TextBox1.SelectionStart = (0)
TextBox1.SelectionLength = (3)
If TextBox1.SelectedText = 300 And TextBox1.Text.Length = 14 Then
TextBox2.Text = " Diners Club"
ElseIf TextBox1.SelectedText = 301 And TextBox1.Text.Length = 14 Then
TextBox2.Text = " Diners Club"
ElseIf TextBox1.SelectedText = 302 And TextBox1.Text.Length = 14 Then
TextBox2.Text = " Diners Club"
ElseIf TextBox1.SelectedText = 303 And TextBox1.Text.Length = 14 Then
TextBox2.Text = " Diners Club"
ElseIf TextBox1.SelectedText = 304 And TextBox1.Text.Length = 14 Then
TextBox2.Text = " Diners Club"
ElseIf TextBox1.SelectedText = 305 And TextBox1.Text.Length = 14 Then
TextBox2.Text = " Diners Club"
Else
diners2()
End If
End Sub
Code: Select all
'-----------------------------------------------------------------------------------------------------------------------------Public Sub diners2()
TextBox1.SelectionStart = (0)
TextBox1.SelectionLength = (2)
If TextBox1.SelectedText = 36 And TextBox1.Text.Length = 14 Then
TextBox2.Text = " Diners Club"
ElseIf TextBox1.SelectedText = 38 And TextBox1.Text.Length = 14 Then
TextBox2.Text = " Diners Club"
Else
discover1()
End If
End Sub
Determine if card is DISCOVER
Code: Select all
Public Sub discover1()
TextBox1.SelectionStart = (0)
TextBox1.SelectionLength = (4)
If TextBox1.SelectedText = 6011 And TextBox1.Text.Length = 16 Then
TextBox2.Text = " Discover Card"
Else
discover2()
End If
End Sub
Public Sub discover2()
TextBox1.SelectionStart = (0)
TextBox1.SelectionLength = (2)
If TextBox1.SelectedText = 65 And TextBox1.Text.Length = 16 Then
TextBox2.Text = " Discover Card"
Else
TextBox2.Text = "Unknown Card"
End If
End Sub
End Class
And now add the following code to the button click event:
visa()
Last edited by MANSQN on Tue Feb 14, 2012 10:23 pm, edited 1 time in total.
It would be better if the user could configure the list of credit card number ranges.
I personnally do not have a use for this, but congrats because this seems to have a use for programs requiring a payment 

3 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023