Test Credit Card - February 2010

If you download this tip please consider making a modest donation.

The application I'm currently working on accepts a credit card which is sent via email to make a reservation. I wanted to make sure that the number passed a preliminary test for validity. So I searched the web and found some code written by Mike Walters that works. The link: http://www.freevbcode.com/ShowCode.asp?ID=5850. I modified the code and added a method to check the expiration date. The code is contained in a module called cCreditCard. It becomes the tip-of-the-month.
 

Although the credit card number and expiration date may pass the tests shown here it does not mean that the credit card is a validly issued card. It only means that the format of the card number or expiration date are valid. It is quite possible that the card will be rejected by the issuer.

VB.Net Demo Solution

I wrote a VS2008 VB.Net Asp.Net Solution to demonstrate the use of cCreditCard:

Using the Demo

Credit Card - Enter a credit card number into the Credit Card field.
Check Credit Card - Click this button to validate the credit card number. A pass or fail message is issued.

Expires mm/yy - Enter the expiration month and year in mm/yy or mm/yyyy format. Leading zeros are required. Enter July as '07'.
Years Behind - Enter the number of years behind the current year which will be used to verify the validity of the expiration year. Default it zero
Years Ahead - Enter the number of years ahead of the current year which will be used to verify the validity of the expiration year. Default is five.
Check Expiration - Click this button to validate the expiration date. A pass or fail message is issued.

Sample Calling Code - Check the Credit Card Number

Dim oCC As New cCreditCard
With oCC
    If .ValidCreditCardNumber(oTxt.Text) Then
       
sMessage = oTxt.Text & " is a valid credit card number."
       
oT.MessageGood(Me.TableMain, sMessage)
   
Else
       
sMessage = oTxt.Text & " is not a valid credit card number."
        oT.MessageError(Me.TableMain, sMessage)
   
End If
End
With

Sample Calling Code - Check the Expiration Date

Dim oCC As New cCreditCard
With oCC
    If .ValidExpirationDate(oTxtExp.Text) Then
       
sMessage = oTxtExp.Text & " is a valid expiration date."
       
oT.MessageGood(Me.TableMain, sMessage)
    Else
       
sMessage = oTxtExp.Text & " is not a valid expiration date."
        oT.MessageError(Me.TableMain, sMessage)
    End If
End
With

Download VB.Net Code

Download - VS2008 Zipped File

 Size 

TestCreditCard TestCreditCard.zip 40k

Previous Tip    Tip Index    Next Tip

Home

Updated 2011/04/16