<% ' Copyright (C) 1998-2005 Cyberstrong Internet Services, Inc. All Rights Reserved ' ' This file has been seeded with unique information at point of sale and ' is traceable to its purchaser. ' ' Your license agreement forbids the removal of this notice. ' ccvalid.asp - Validate credit card number ' IsCCValid - Is credit card number valid? Public Function IsCCValid(ByVal asCardType, ByVal anCardNumber) ' Performs a Mod 10 check to make sure the credit card number ' appears valid ' Developers may use the following numbers as dummy data: ' Visa: 430-00000-00000 ' American Express: 372-00000-00000 ' Mastercard: 521-00000-00000 ' Discover: 620-00000-00000 Dim lsNumber ' Credit card number stripped of all spaces, dashes, etc. Dim lsChar ' an individual character Dim lnTotal ' Sum of all calculations Dim lnDigit ' A digit found within a credit card number Dim lnPosition ' identifies a character position in a string Dim lnSum ' Sum of calculations for a specific set Dim lnMultiplier ' Default result is false IsCCValid = False ' ==== ' Strip all characters that are not numbers. ' ==== ' Loop through each character inthe card number submited For lnPosition = 1 To Len(anCardNumber) ' Grab the current character lsChar = Mid(anCardNumber, lnPosition, 1) ' If the character is a number, append it to our new number If IsNumeric(lsChar) Then lsNumber = lsNumber & lsChar Next ' lnPosition ' ==== ' The credit card number must be between 13 and 16 digits. ' ==== ' If the length of the number is less then 13 digits, then exit the routine If Len(lsNumber) < 13 Then Exit Function ' If the length of the number is more then 16 digits, then exit the routine If Len(lsNumber) > 16 Then Exit Function ' ==== ' The credit card number must start with: ' 4 for Visa Cards ' 37 for American Express Cards ' 5 for MasterCards ' 6 for Discover Cards ' ==== ' Choose action based on type of card Select Case Trim(LCase(asCardType)) ' VISA Case "visa", "v" ' If first digit not 4, exit function If Not Left(lsNumber, 1) = "4" Then Exit Function ' American Express Case "american express", "americanexpress", "american", "ax" ' If first 2 digits not 37, exit function If Not Left(lsNumber, 2) = "37" Then Exit Function ' Mastercard Case "mastercard", "master card", "master", "m" ' If first digit not 5, exit function If Not Left(lsNumber, 1) = "5" Then Exit Function ' Discover Case "discover", "discovercard", "discover card", "d" ' If first digit not 6, exit function If Not Left(lsNumber, 1) = "6" Then Exit Function End Select ' LCase(asCardType) ' ==== ' If the credit card number is less then 16 digits add zeros ' to the beginning to make it 16 digits. ' ==== ' Continue loop while the length of the number is less then 16 digits While Not Len(lsNumber) = 16 ' Insert 0 to the beginning of the number lsNumber = "0" & lsNumber Wend ' Not Len(lsNumber) = 16 ' ==== ' Multiply each digit of the credit card number by the corresponding digit of ' the mask, and sum the results together. ' ==== ' Loop through each digit For lnPosition = 1 To 16 ' Parse a digit from a specified position in the number lnDigit = Mid(lsNumber, lnPosition, 1) ' Determine if we multiply by: ' 1 (Even) ' 2 (Odd) ' based on the position that we are reading the digit from lnMultiplier = 1 + (lnPosition Mod 2) ' Calculate the sum by multiplying the digit and the Multiplier lnSum = lnDigit * lnMultiplier ' (Single digits roll over to remain single. We manually have to do this.) ' If the Sum is 10 or more, subtract 9 If lnSum > 9 Then lnSum = lnSum - 9 ' Add the sum to the total of all sums lnTotal = lnTotal + lnSum Next ' lnPosition ' ==== ' Once all the results are summed divide ' by 10, if there is no remainder then the credit card number is valid. ' ==== IsCCValid = ((lnTotal Mod 10) = 0) End Function ' IsCCValid ' IsExpireDateValid() - Test expire date for validity Public Function IsExpireDateValid(ByVal argExpireDate, ByRef argErrorMsg) Dim Year, Month, ExpireDateSerial, d IsExpireDateValid = False argErrorMsg = "Expiration date must be of the form MM/YY" If (Not isMatch(argExpireDate, "^\d\d/\d\d$")) Then Exit Function Month = CSng(Mid(argExpireDate, 1, 2)) Year = CSng(Mid(argExpireDate, 4, 2)) If ((Year < 0) OR (Year > 99)) Then Exit Function If ((Month < 0) OR (Month > 12)) Then Exit Function argErrorMsg = "Expiration date must be in the future" ' Use first day of next month - 1 for expire date Month = Month + 1 If Month > 12 Then Month = 1 Year = Year + 1 End If ExpireDateSerial = DateSerial(2000 + Year, Month, 1) - 1 If ExpireDateSerial < Date() Then Exit Function argErrorMsg = "" IsExpireDateValid = True End Function %>