Important alert: (current site time 7/16/2013 4:15:13 AM EDT)
 

VB icon

Credit Card Identification

Email
Submitted on: 5/27/1998
By: John Anderson  
Level: Not Given
User Rating: By 2 Users
Compatibility: VB 3.0, VB 4.0 (16-bit), VB 4.0 (32-bit), VB 5.0, VB 6.0
Views: 27936
 
     Determines type of Credit Card by it's number.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: Credit Card Identification
' Description:Determines type of Credit Card by it's number.
' By: John Anderson
'
' Inputs:Card Number as String
'
' Returns:Card Type as String
'
' Assumes:This is based on documents from CyberCash's home page.
'
' Side Effects:Is not Year 2061 Compliant
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=903&lngWId=1'for details.'**************************************

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


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Not Given category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

4/14/1999 12:36:00 AMleyo

Do you also have a code that also checks the card expiraton? coz' I got a code in jscript that has it, but I can't understand it.
(If this comment was disrespectful, please report it.)

 
5/1/1999 3:17:00 PMJamesredwood

Yeah, Can we have some expiration date code Please. Useless without.
(If this comment was disrespectful, please report it.)

 
5/14/1999 8:53:00 AMEric Paulson

Very useful algorithm!
(If this comment was disrespectful, please report it.)

 
5/18/1999 1:14:00 PMTimothy Duemig

I've written many routines like this... for all of you wanting to know the date validation simply read in the date as a string by using a combination of instr(), mid(), left(), and right(). Use the Replace function to change char(s) when needed.
(If this comment was disrespectful, please report it.)

 
7/19/1999 1:30:00 PMlisa

just what I needed, thanks!

(If this comment was disrespectful, please report it.)

 
9/15/1999 5:52:00 PMhey

Tim: Your answer to the date questions do not help at all, could you just post the date code too? thanks!
(If this comment was disrespectful, please report it.)

 
10/28/1999 6:20:00 PMdoo

what buttuns and other stuff do i need on the form?
(If this comment was disrespectful, please report it.)

 
2/19/2000 6:38:03 AMjeff

how would i make a textbox display the card type?
(If this comment was disrespectful, please report it.)

 
7/6/2000 9:34:56 AMDetonate

jeff:
Text1.Text = CardType("5353000000000000")

John, good submission :-)

(If this comment was disrespectful, please report it.)

 
6/23/2005 9:43:27 PM

Can we identify in which Country the Card was issued?

Thanks,
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.