Need to determine a credit card type? Can注释:t be bothered to write your own decision-making function?
Fear not - hear to help is our own ready-to-run code snippet. Just feed it a credit card number and it注释:ll return a string of the appropriate card type.
If you want to determine whether a credit card number is valid, check out our handy code snippet here.
Usage
x = CreditCardType("5454 1234 4321 1234")Code
Public Function CreditCardType(ByVal CardNo As String) As String
注释:Just in case nothing is found CreditCardType = "Unknown"
注释:Remove all spaces and dashes from the passed string CardNo = Replace(Replace(CardNo, " ", ""), "-", "")
注释:Check that the minimum length of the string isn注释:t less 注释:than fourteen characters and -is- numeric If Len(CardNo) < 14 Or Not IsNumeric(CardNo) Then Exit Function
注释:Check the first two digits first Select Case CInt(Left(CardNo, 2)) Case 34, 37 CreditCardType = "American Express" Case 36 CreditCardType = "Diners Club" Case 38 CreditCardType = "Carte Blanche" Case 51 To 55 CreditCardType = "Master Card" Case Else
注释:None of the above - so check the 注释:first four digits collectively Select Case CInt(Left(CardNo, 4))
Case 2014, 2149 CreditCardType = "EnRoute" Case 2131, 1800 CreditCardType = "JCB" Case 6011 CreditCardType = "Discover" Case Else
注释:None of the above - so check the 注释:first three digits collectively Select Case CInt(Left(CardNo, 3)) Case 300 To 305 CreditCardType = "American Diners Club" Case Else
注释:None of the above - 注释:so simply check the first digit Select Case CInt(Left(CardNo, 1)) Case 3 CreditCardType = "JCB" Case 4 CreditCardType = "Visa" End Select