Results 1 to 2 of 2

Thread: Can U Figure this problem out?

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2001
    Location
    Florida
    Posts
    3,216

    Thumbs down

    If anybody has the time please look at this credit card validation function and tell me if you can find out why the results given back to me from the function are duplicated? For example I get 2 Mastercard names and account numbers returned. I only need one name and number returned not 2!

    <%
    Function ValidateCreditCard(ByRef pStrNumber, ByRef pStrType)

    ValidateCreditCard = False ' Initialize negative results

    ' Clean Credit Card Number (Removes dashes and spaces)
    pStrNumber = ParseDigits(pStrNumber)

    ' Validate number with LUHN Formula
    If Not LUHN(pStrNumber) Then Exit Function

    ' Apply rules based on type of card
    Select Case pStrType
    Case "American Express"
    Select Case Left(pStrNumber, 2)
    Case "34", "37"
    ' Do Nothing
    Case Else
    Exit Function
    End Select
    If Not Len(pStrNumber) = 15 Then Exit Function
    Case "Diners Club"
    Select Case Left(pStrNumber, 2)
    Case "36" , "38"
    ' Do Nothing
    Case "30"
    Select Case Left(pStrNumber, 3)
    Case "300", "301", "302", "303", "304", "305"
    ' Do Nothing
    Case Else
    Exit Function
    End Select
    Case Else
    Exit Function
    End Select
    If Not Len(pStrNumber) = 14 Then Exit Function
    Case "Discover"
    If Not Left(pStrNumber, 4) = "6011" Then Exit Function
    If Not Len(pStrNumber) = 16 Then Exit Function
    Case "JCB"
    If Left(pStrNumber, 1) = "3" And Len(pStrNumber) = 16 Then
    ' Do Nothing
    ElseIf Left(pStrNumber, 14) = "2131" And Len(pStrNumber) = 15 Then
    ' Do Nothing
    ElseIf Left(pStrNumber, 14) = "1800" And Len(pStrNumber) = 15 Then
    ' Do Nothing
    Else
    Exit Function
    End If
    Case "Mastercard"
    Select Case Left(pStrNumber, 2)
    Case "51", "52", "53", "54", "55"
    ' Do Nothing
    Case Else
    Exit Function
    End Select
    If Not Len(pStrNumber) = 16 Then Exit Function
    Case "Visa"
    If Not Left(pStrNumber, 1) = "4" Then Exit Function
    If Not (Len(pStrNumber) = 13 Or Len(pStrNumber) = 16) Then Exit Function
    Case Else
    ' Unknown Card Type
    Exit Function
    End Select

    ' We got this far so the number passed all the rules!
    ValidateCreditCard = True

    End Function
    ' ------------------------------------------------------------------------------
    Function LUHN(ByRef pStrDigits)

    Dim lLngMaxPosition
    Dim lLngPosition
    Dim lLngSum ' Sum of all positions
    Dim lLngDigit ' Current digit in specified position

    ' Initialize
    lLngMaxPosition = Len(pStrDigits)
    lLngSum = 0

    ' Read from right to left
    For lLngPosition = lLngMaxPosition To 1 Step -1

    ' If we are working with an even digit (from the right)
    If (lLngMaxPosition - lLngPosition) Mod 2 = 0 Then

    lLngSum = lLngSum + CInt(Mid(pStrDigits, lLngPosition, 1))

    Else

    ' Double the digit
    lLngDigit = CInt(Mid(pStrDigits, lLngPosition, 1)) * 2

    ' shortcut adding sum of digits
    If lLngDigit > 9 Then lLngDigit = lLngDigit - 9

    lLngSum = lLngSum + lLngDigit

    End If
    Next

    ' A mod 10 check must not return any remainders
    LUHN = lLngSum Mod 10 = 0

    End Function
    ' ------------------------------------------------------------------------------
    Function ParseDigits(ByRef pStrData)

    ' Strip all the numbers from a string
    ' (cleans up dashes and spaces)

    Dim lLngMaxPosition
    Dim lLngPosition

    lLngMaxPosition = Len(pStrData)

    For lLngPosition = 1 To lLngMaxPosition
    If IsNumeric(Mid(pStrData, lLngPosition, 1)) Then
    ParseDigits = ParseDigits & Mid(pStrData, lLngPosition, 1)
    End If
    Next

    End Function
    ' ------------------------------------------------------------------------------
    %>

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    If you expect anyone to have any hope of debugging that, use [code][/code] tags to preserve the indentation and general formatting
    Harry.

    "From one thing, know ten thousand things."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width