CFLib.org – Common Function Library Project

getCardType(cardNumber)

Last updated November 3, 2005

author

Dave Cordes

Version: 1 | Requires: CF5 | Library: UtilityLib

Description:
Returns the card type of a card number. Will return "Unknown" if the card type cannot be detected.

Return Values:
Returns a string.

Example:

<cfoutput>
What card type is 4111111111111111? #GetCardType(4111111111111111)#
</cfoutput>

Parameters:

Name Description Required
cardNumber The credit card number. Yes

Full UDF Source:

/**
 * Returns the card type of a card number.
 * 
 * @param cardNumber 	 The credit card number. (Required)
 * @return Returns a string. 
 * @author Dave Cordes (dcordes@apoktechnology.com) 
 * @version 1, November 3, 2005 
 */
function getCardType(cardNumber) {
	var CardType = "Unknown";
	var CardLength = Len(cardNumber);
	
	if ((CardLength eq 15) and (((Left(cardNumber, 2) is "34")) or ((Left(cardNumber, 2) is "37")))) CardType = "American Express";
	if ((CardLength eq 14) and (((Left(cardNumber, 3) gte 300) and (Left(cardNumber, 3) lte 305)) or (Left(cardNumber, 2) is "36") or (Left(cardNumber, 2) is "38"))) CardType =  "Diner's Club";
	if ((CardLength eq 16) and (Left(cardNumber, 4) is "6011")) CardType =  "Discover Card";
	if ((CardLength eq 16) and (Left(cardNumber, 2) gte 51) and (Left(cardNumber, 2) lte 55)) CardType =  "MasterCard";
	if (((CardLength eq 13) or (CardLength eq 16)) and (Left(cardNumber, 1) is "4")) CardType =  "Visa";
	
	return CardType;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson