Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ASP Credit Card Validation

Posted on 1998-09-16
2
Medium Priority
?
385 Views
Last Modified: 2013-12-20
How do you validate credit card info using ASP
I would like to check both number & expiry.
I do NOT require credit card processing, validation only.
0
Comment
Question by:hamishd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
MasseyM earned 200 total points
ID: 1855095
Here is the HTML:


<html>
<head>
<title>Credit Card Number Verification</title>
<script LANGUAGE="vbscript">
'
'Create two variables with global scope
'
     Dim paymethod
     Dim TheCardType

'
'This is the main sub routine and is called by the button's onclick event handler
'
Sub VerifyCard
    dim strCleanNo
    dim verified
    dim currdate

 'check the date if bad then quit
 If Not GoodDate() Then
  Exit Sub
 End If

 'take all spaces etc out of the string
 strCleanNo = CleanString()

 'determine the type of card and send execution off in the right direction
 Select Case TheCardType
 Case "amex"
     verified = verifyAmex(strCleanNo)
 Case "visa"

     'this is a nested select
     Select Case Len(strCleanNo)
     Case 13
          verified = verifyV(strCleanNo)
     Case 16
          verified = verifyMC(strCleanNo)
     Case Else
          verified = False
     End Select

 Case "mastercard"
     verified = verifyMC(strCleanNo)
 Case "discovery"
     verified = verifyMC(strCleanNo)
 Case Else
     Alert  "Please select a Card Type"
     Exit Sub
 End Select

 'is it ok or not?
 If Not verified Then
     i = MsgBox("INVALID CARD NUMBER",16,"Cannot Submit Data")
 Else
     i = MsgBox("The Card No. is OK",64,"Submitting Data....")
 End If
End Sub

'
'This is the function that checks the date
'
Function GoodDate()
 GoodDate = True
 If Not IsDate(Document.Form1.CardExp.Value) Then
     i = MsgBox("Invalid Expiry Date",16,"Cannot Submit Data")
     GoodDate = False
 Else
     currdate = Month(Now()) & " " & Year(Now())
     If DateValue(Document.Form1.CardExp.Value) < DateValue(currdate) Then
          i = MsgBox("THIS CARD HAS EXPIRED",16,"Cannot Submit Data")
          GoodDate = False
     End If
 End If
End Function

'
'This function validates an amex card
'
Function VerifyAmex(ByVal CardNo)
    Dim amexarray(14)
    Dim tot
    tot=0

 If Len(CardNo) <> 15 Then
     VerifyAmex = False
     Exit Function
 End If

 For x = 2 to 10 step 2
     amexarray(x-1) = Mid(CardNo,x,1)
 Next
 
 For x = 12 to 15
     amexarray(x-1) = Mid(CardNo,x,1)
 Next

 For x = 1 to 11 Step 2
     y = Mid(CardNo,x,1) * 2
     If y >= 10 Then
         amexarray(x-1) =  (y Mod 10) + 1
     Else
         amexarray(x-1) = y
     End If
 Next
 
 For x = 0 to 14
     tot = tot + CInt(amexarray(x))
 Next

 If tot Mod 10 = 0 Then
     VerifyAmex = True
 Else
     VerifyAmex = False
 End If
 
End Function

'
'This function checks visa 13 digit cards
'
Function VerifyV(ByVal CardNo)
    Dim vArray(12)
    Dim tot
    tot=0

 For x = 2 to 12 step 2
     vArray(x-1) = Mid(CardNo,x,1)
 Next
     vArray(12) = Mid(CardNo,13,1)
 
 'Mod returns the remainder of a division
 For x = 1 to 11 Step 2
     y = Mid(CardNo,x,1) * 2
     If y >= 10 Then
         vArray(x-1) =  (y Mod 10) + 1
     Else
         vArray(x-1) = y
     End If
 Next
 
 For x = 0 to 12
     tot = tot + CInt(vArray(x))
 Next

 If tot Mod 10 = 0 Then
     VerifyV = True
 Else
     VerifyV = False
 End If
 
End Function

'
'Although it says MC it's actually a multi purpose 16 digit checker
'
Function VerifyMC(ByVal CardNo)
    Dim tot
    tot=0


 If Len(CardNo) <> 16 Then
     VerifyMC = False
     Exit Function
 End If

 For x = 2 to 16 step 2
     tot = tot + CInt(Mid(CardNo,x,1))
 Next

 For x = 1 to 15 Step 2
     y = Mid(CardNo,x,1) * 2
     If y >= 10 Then
         tot = tot + CInt((y Mod 10) + 1)
     Else
         tot = tot + CInt(y)
     End If
 Next
 
 If tot Mod 10 = 0 Then
     VerifyMC = True
 Else
     VerifyMC = False
 End If

End Function

'
'This function looks for numbers in the card number string, thereby
'removing all non numeric characters
'
Function CleanString()
    dim strLen
    dim strCounter
    dim strClean
    dim strDirty
 
 strDirty = Trim(Document.Form1.cardnumber.value)
 strLen = Len(strDirty)
 strClean = ""
 
 For strCounter = 1 to strLen
    If Asc(Mid(strDirty,strCounter,1)) < 58 AND Asc(Mid(strDirty,strCounter,1)) > 47 Then
        strClean = strClean  & Mid(strDirty,strCounter,1)
    End If
 Next

 CleanString = strClean
End Function

'et voila
</script>

</head>
<body BACKGROUND="bground.jpg">
<font FACE="arial" SIZE="2">
<center>
<table>
<td><img SRC="visa.gif" WIDTH="64" HEIGHT="43">
<td><img SRC="master.gif" WIDTH="72" HEIGHT="43">
<td><img SRC="amex.gif" WIDTH="43" HEIGHT="43">
</table>
<p>
<br><br>
<blockquote>
If you are paying by credit card, please complete this section
of the form.
</blockquote>
    <form NAME="Form1">

<table>
<td ALIGN="RIGHT"><b>Visa</b>
<td>
<input LANGUAGE="vbscript" TYPE="RADIO" VALUE="visa" ONCLICK="TheCardType= &quot;visa&quot;" NAME="cardtype">

<td ALIGN="RIGHT"><b>Mastercard</b>
<td><input LANGUAGE="vbscript" TYPE="RADIO" VALUE="mastercard" ONCLICK="TheCardType= &quot;mastercard&quot;" NAME="cardtype">
<tr>
<td ALIGN="RIGHT"><b>American Express</b>
<td><input LANGUAGE="vbscript" TYPE="RADIO" VALUE="amex" ONCLICK="TheCardType= &quot;amex&quot;" NAME="cardtype">

<td ALIGN="RIGHT"><b>Discover</b>
<td><input LANGUAGE="vbscript" TYPE="RADIO" VALUE="discovery" ONCLICK="TheCardType= &quot;discovery&quot;" NAME="cardtype">
<tr>
</table>
<p>
<table>
<td><b>Cardholder's Name</b>
<td><input TYPE="TEXT" SIZE="30" NAME="cardholder">
<tr>
<td><b>Card Number</b>
<td><input TYPE="TEXT" SIZE="20" NAME="cardnumber">
<tr>
<td><b>Card Expiration Date</b>
<td><input TYPE="TEXT" SIZE="5" NAME="cardexp">
<tr>
</table>
<p>
        <input LANGUAGE="vbscript" TYPE="button" VALUE="Check" ONCLICK=" call VerifyCard()">
        <input TYPE="RESET" VALUE="Clear/Reset">
    </form>
<br><br>

<font SIZE="1"><i>
This example appears courtesy of SAMS.NET<br>
from the book
<a HREF="../../books.htm">
<b>Laura Lemay's Web Workshop: ActiveX and VBScript</b>
</a>
<br>
by Paul Lomax
</i>
</font>

</body>
</html>
0
 

Author Comment

by:hamishd
ID: 1855096
The credit card validation must occur within a CGI script. Do you have a CC validation in ASP?

There is a security issue validating CC's using javascript.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
This tutorial demonstrates how to identify and create boundary or building outlines in Google Maps. In this example, I outline the boundaries of an enclosed skatepark within a community park.  Login to your Google Account, then  Google for "Google M…
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question