Results 1 to 4 of 4

Thread: Mod 10 Function

  1. #1

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

    Talking

    I found a Mod10 script that checks the numbers in a given credit card.

    <%

    Function IsCreditCard(ByRef asCardType, ByRef anCardNumber)

    ' Performs a Mod 10 check to make sure the credit card number
    ' appears valid
    My question is this?

    THe asCardType and anCardNumber are they variables that I name based on the textboxes name that contain the data on the previous form?

  2. #2
    New Member
    Join Date
    Feb 2001
    Posts
    12
    Do you have the rest of the coding for that function, mayb it could help to check???

  3. #3

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

    Talking

    Sure

    <%

    Function IsCreditCard(ByRef lstCreditCard, ByRef txtAccountNumber)'asCardType, 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


    txtReg1FirstName=request.form("txtReg1FirstName")
    txtReg1LastName=request.form("txtReg1LastName")
    lstReg1Type=request.form("lstReg1Type")
    txtReg1Badge=request.form("txtReg1Badge")

    txtFirstName=request.form("txtFirstName")
    txtLastName=request.form("txtLastName")
    txtAddress=request.form("txtAddress")
    txtCity=request.form("txtCity")
    lstState=request.form("lstState")
    txtZip=request.form("txtZip")
    txtPhone=request.form("txtPhone")
    lstCreditCard=request.form("lstCreditCard")
    txtAccountNumber=request.form("txtAccountNumber")
    txtExpDate=request.form("txtExpDate")

    ' Default result is false
    IsCreditCard = False

    ' ====
    ' Strip all characters that are not numbers.
    ' ====

    ' Loop through each character in the card number submited
    For lnPosition = 1 To Len(txtAccountNumber)

    ' Grab the current character
    lsChar = Mid(txtAccountNumber, 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
    Response.Redirect "../mod10/moderror.asp"
    Exit Function

    ' If the length of the number is more then 16 digits, then exit the routine
    Else If Len(lsNumber) > 16 Then
    Response.Redirect "../mod10/moderror.asp"
    Exit Function

    End If
    End If


    ' ====
    ' 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 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", "a"

    ' 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

    Case Else

    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.
    ' ====

    IsCreditCard = ((lnTotal Mod 10) = 0)

    End Function ' IsCreditCard

    %>

  4. #4
    New Member
    Join Date
    Feb 2001
    Posts
    12
    Sorry , can you show me the part of the coding where you call up that function, cuze for sure it received 2 values coming from somewhere

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