Credit Card Identification

By | 2002-06-01

Determines type of Credit Card by it’s number.

Original Author: John Anderson

Inputs

Card Number as String

Assumptions

This is based on documents from CyberCash’s home page.

Returns

Card Type as String

Side Effects

Is not Year 2061 Compliant

API Declarations

Code

Public Function CardType(CCNum As String) As String
Dim Header As String
  Select Case Left$(CCNum, 1)
    Case "5"
      Header = Left$(CCNum, 2)
      If Header >= 51 And Header <= 55 And Len(CCNum) = 16 Then
        CardType = "MasterCard"
      End If
    Case "4"
      If Len(CCNum) = 13 Or Len(CCNum) = 16 Then
        CardType = "Visa"
      End If
    Case "3"
      Header = Left$(CCNum, 3)
      If Header >= 340 And Header <= 379 And Len(CCNum) = 15 Then
        CardType = "AMEX"
      End If
      If Header >= 300 And Header <= 305 And Len(CCNum) = 14 Then
        CardType = "Diners Club"
      End If
      If Header >= 360 And Header <= 369 And Len(CCNum) = 14 Then
        CardType = "Diners Club"
      End If
      If Header >= 380 And Header <= 389 And Len(CCNum) = 14 Then
        CardType = "Diners Club"
      End If
      If Header >= 300 And Header <= 399 And Len(CCNum) = 16 Then
        CardType = "JCB"
      End If
    Case "6"
      Header = Left$(CCNum, 4)
      If Header = "6011" And Len(CCNum) = 16 Then
        CardType = "Discover"
      End If
    Case "2"
      Header = Left$(CCNum, 4)
      If (Header = "2014" Or Header = "2149") And Len(CCNum) = 15 Then
        CardType = "enRoute"
      End If
      If Header = "2131" And Len(CCNum) = 15 Then
        CardType = "JCB"
      End If
    Case "1"
      Header = Left$(CCNum, 4)
      If Header = "1800" And Len(CCNum) = 15 Then
        CardType = "JCB"
      End If
  End Select
  If CardType = "" Then CardType = "Unknown"
End Function

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.