IsWorthy Function:

The IsWorthy function checks a credit card number against strict credit card standards. IsWorthy returns True if the credit card has been verified or False if the credit card has not been verified. There are three required arguments, CreditCardType, CreditCardNumber and ExpirationDate. CreditCardType must be one of the following Integer values representing one of the seven credit card types recognized by IsWorthy:
Credit Card Type Acceptable integer argument
for CreditCardType
MasterCard 1
Visa 2
American Express 3
Diner's Club / Carte Blanche 4
Discover 5
En Route 6
JCB 7

CreditCardNumber should be a string or long representing a credit card number to be verified. ExpirationDate must be in the form (mm/yy) and should reflect a valid date.

Syntax:
boolean = IsWorthy(CreditCardType, CreditCardNumber, ExpirationDate)
Example Usage:
<%
Const MasterCard = 1, Visa = 2, Amex = 3, DC_CB = 4
Const Discover = 5, EnRoute = 6, JCB = 7
%>

<%  = IsWorthy(MasterCard, "5400000000000000", "10/03")  %>
IsWorthy returns True.

<%  = IsWorthy(Amex, "123456789", "10/03")  %>
IsWorthy returns False.
ASP Source Code:
<%
Private Function IsWorthy(byVal strCardType, _
    byVal strCCNumber, byVal dExpDate)
	Dim strCCFirstFour, RequiredDigits, strCCFirstTwo, i, dMonth
	Dim bBadDigits, strCCFirstThree, iRequiredLength, TodaysDate
	Dim bNumberVerified, bVisaPresent, AbsoluteCCExpirationDate, dYear
	strCCNumber = CSTR(strCCNumber)  :  strCCNumber = _
	    replace(strCCNumber, " ", "")
	strCCNumber = replace(strCCNumber, "-", "")
	if isNumeric(strCCNumber) = False Then _
		IsWorthy = False  :  Exit Function
	strCardType = CINT(strCardType)  :  strCCFirstFour = Left(strCCNumber, 4)
	Select Case strCardType
		Case 1
			RequiredDigits = Array("51", "52", "53", _
					 "54", "55")
			strCCFirstTwo = Left(strCCFirstFour, 2)
			For i = 0 to Ubound(RequiredDigits)
				if CSTR(RequiredDigits(i)) = _
				    CSTR(strCCFirstTwo) then
					bBadDigits = False
					Exit For
				else
					bBadDigits = True
				end if
			Next
		Case 2
			RequiredDigits = 4
			if CSTR(RequiredDigits) = _
			    CSTR(Left(strCCFirstFour, 1)) then
				bBadDigits = False
			else
				bBadDigits = True
			end if
		Case 3
			RequiredDigits = Array("34", "37")
			strCCFirstTwo = Left(strCCFirstFour, 2)
			For i = 0 to Ubound(RequiredDigits)
				if CSTR(RequiredDigits(i)) = _
				    CSTR(strCCFirstTwo) then
					bBadDigits = False
					Exit For
				else
					bBadDigits = True
				end if
			Next
		Case 4
			RequiredDigits = Array("300", "301", "302", "303", _
					 "304", "305", "36", "38")
			strCCFirstThree = Left(strCCFirstFour, 3)
			For i = 0 to 5
				if CSTR(RequiredDigits(i)) = _
				    CSTR(strCCFirstThree) then
					bBadDigits = False
					Exit For
				else
					bBadDigits = True
				end if
			Next
			If bBadDigits = True then
				strCCFirstTwo = Left(strCCFirstFour, 2)
				For i = 6 to Ubound(RequiredDigits)
					if CSTR(RequiredDigits(i)) = _
					    CSTR(strCCFirstTwo) then
						bBadDigits = False
						Exit For
					else
						bBadDigits = True
					end if
				Next
			End If
		Case 5
			RequiredDigits = 6011
			if CSTR(RequiredDigits) = _
			    CSTR(strCCFirstFour) then
				bBadDigits = False
			else
				bBadDigits = True
			end if
		Case 6
			RequiredDigits = Array("2014", "2149")
			For i = 0 to Ubound(RequiredDigits)
				if CSTR(RequiredDigits(i)) = _
				    CSTR(strCCFirstFour) then
					bBadDigits = False
					Exit For
				else
					bBadDigits = True
				end if
			Next
		Case 7
			RequiredDigits = Array("3", "2131", "1800")
			if CSTR(Left(strCCFirstFour, 1)) = _
			    CSTR(RequiredDigits(0)) then
				bBadDigits = False
			else
				For i = 1 to Ubound(RequiredDigits)
					if CSTR(RequiredDigits(i)) = _
					    CSTR(strCCFirstFour) then
						bBadDigits = False
						Exit For
					else
						bBadDigits = True
					end if
				Next
			end if
		Case Else
			bBadDigits = True
	End Select
	if bBadDigits Then 
		IsWorthy = False  :  Exit Function
	end if
	bVisaPresent = False
	Select Case strCardType
		Case 1
			iRequiredLength = 16
		Case 2
			bVisaPresent = True
			if Int(Len(strCCNumber)) = Int(16) _
			OR Int(Len(strCCNumber)) = Int(13) then
				bNumberVerified = True
			else
				IsWorthy = False  :  Exit Function
			end if
		Case 3
			iRequiredLength = 15
		Case 4
			iRequiredLength = 14
		Case 5
			iRequiredLength = 16
		Case 6
			iRequiredLength = 15
		Case 7
			if Int(Left(strCCNumber,1)) = Int(3) then
				iRequiredLength = 16
			else
				iRequiredLength = 15
			end if
		Case Else
			IsWorthy = False  :  Exit Function
	End Select
	if bVisaPresent = False then
		if Int(Len(strCCNumber)) = Int(iRequiredLength) then
			bNumberVerified = True
		else
			bNumberVerified = False
		end if
	end if
	if bNumberVerified = False then _
		IsWorthy = False  :  Exit Function
	dExpDate = Trim(dExpDate)
	if instr(dExpDate,"/") Then 
		AbsoluteCCExpirationDate = Split(dExpDate, "/")
	elseif instr(dExpDate,"-") Then 
		AbsoluteCCExpirationDate = Split(dExpDate, "-")
	elseif instr(dExpDate," ") Then 
		AbsoluteCCExpirationDate = Split(dExpDate, " ")
	else
		IsWorthy = False  :  Exit Function
	end if
	if Ubound(AbsoluteCCExpirationDate) > 1 then _
		IsWorthy = False  :  Exit Function
	TodaysDate = split(formatdatetime(date(),2), "/")
	dMonth = Int(TodaysDate(0))  :  dYear = Int(TodaysDate(2))
	if Int(dYear) = Int(AbsoluteCCExpirationDate(1)) then
		if Int(dMonth) > Int(AbsoluteCCExpirationDate(0)) then
			IsWorthy = False  :  Exit Function
		else
			IsWorthy = True   :  Exit Function
		end if
	else
		if Int(dYear) > Int(AbsoluteCCExpirationDate(1)) then
			IsWorthy = False  :  Exit Function
		else
			IsWorthy = True   :  Exit Function
		end if
	end if
End Function
%>