|
-
Mar 5th, 2001, 09:20 AM
#1
Thread Starter
PowerPoster
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 numbers returned. I am using VBScript. I use :
lstCreditCard=request.form("lstCreditCard")
txtAccountNumber=request.form("txtAccountNumber")
to get the form results. Then I call the function with this code:
gStrNumber = request.form("txtAccountNumber")
gStrType = request.form("lstCreditCard")
gBolPassed = ValidateCreditCard ' Function call
(gStrNumber, gStrType)
Response.Write "Number = " & gStrNumber & "<BR>"
Response.Write "Type = " & gStrType & "<BR>"
Response.Write "Passed = " & gBolPassed & "<BR>"
Above test the results passed back from the function!
Here is what the results looks like:
Number = 54245804752294335424580475229433 'not real
Type = Mastercard, Mastercard
Passed = False
See how it's duplicated? Why is this?
Below is he function code
<%
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
' ------------------------------------------------------------------------------
%>
-
Mar 5th, 2001, 11:04 AM
#2
Thread Starter
PowerPoster
results are being duplicated! Help
I ma using the hidden fields within html to pass data from form to form. I have a new problem I hope you can answer. When I finally process the data by sending it to an .asp page that receives the data, like so:
<!-- #INCLUDE FILE="../data.asp" -->
<!-- #INCLUDE FILE="var.asp" -->
<!-- #INCLUDE FILE="../Mod10/mod10.asp" -->
<!-- #INCLUDE FILE="EarlyPrice.asp" -->
<!-- #INCLUDE FILE="RegPrice.asp" -->
<% Response.Buffer = true %>
<%
'-- Declare your variables
Dim DataConnection, cmdDC, RecordSet, SQL, strError
Dim MyDate
Dim gStrNumber
Dim gStrType
Dim gBolPassed
'-- Get the data from the form
'lstCreditCard=request.form("lstCreditCard")
'txtAccountNumber=request.form("txtAccountNumber")
txtExpDate=request.form("txtExpDate")
'-- Call the Credit Card Function
gStrNumber = Request.Form("txtAccountNumber")
gStrType = Request.Form("lstCreditCard")
gBolPassed = ValidateCreditCard(gStrNumber, gStrType)
Response.Write "Number = " & gStrNumber & "<BR>"
Response.Write "Type = " & gStrType & "<BR>"
Response.Write "Passed = " & gBolPassed & "<BR>"
I am first validating a credit card number using a function that I know is working properly but the problem lies in the fact that when I check the results of the function using the reponse.write command it shows these results:
Number = 54221804752224355424180475222433 'number not real
Type = Mastercard, Mastercard
Passed = False
Do you know why the results are duplicated?
-
Mar 5th, 2001, 11:04 AM
#3
Thread Starter
PowerPoster
I ma using the hidden fields within html to pass data from form to form. I have a new problem I hope you can answer. When I finally process the data by sending it to an .asp page that receives the data, like so:
<!-- #INCLUDE FILE="../data.asp" -->
<!-- #INCLUDE FILE="var.asp" -->
<!-- #INCLUDE FILE="../Mod10/mod10.asp" -->
<!-- #INCLUDE FILE="EarlyPrice.asp" -->
<!-- #INCLUDE FILE="RegPrice.asp" -->
<% Response.Buffer = true %>
<%
'-- Declare your variables
Dim DataConnection, cmdDC, RecordSet, SQL, strError
Dim MyDate
Dim gStrNumber
Dim gStrType
Dim gBolPassed
'-- Get the data from the form
'lstCreditCard=request.form("lstCreditCard")
'txtAccountNumber=request.form("txtAccountNumber")
txtExpDate=request.form("txtExpDate")
'-- Call the Credit Card Function
gStrNumber = Request.Form("txtAccountNumber")
gStrType = Request.Form("lstCreditCard")
gBolPassed = ValidateCreditCard(gStrNumber, gStrType)
Response.Write "Number = " & gStrNumber & "<BR>"
Response.Write "Type = " & gStrType & "<BR>"
Response.Write "Passed = " & gBolPassed & "<BR>"
I am first validating a credit card number using a function that I know is working properly but the problem lies in the fact that when I check the results of the function using the reponse.write command it shows these results:
Number = 54221804752224355424180475222433 'number not real
Type = Mastercard, Mastercard
Passed = False
Do you know why the results are duplicated?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|