//  home   //  advanced search   //  news   //  categories   //  sql build chart   //  downloads   //  statistics
 ASP FAQ 
Home
ASP FAQ Tutorials

   8000XXXX Errors
   ASP.NET 2.0
   Classic ASP 1.0
      COM / ActiveX Components
      Forms
      General Topics
      Date/Time Routines
      Email Scripts & Info
      Files/Directories & FSO
   Databases
   General Concepts
   Search Engine Optimization (SEO)

Contact Us
Site Map

Search

Web
aspfaq.com
tutorials.aspfaq.com
classicasp.aspfaq.com

ASP FAQ Tutorials :: Classic ASP 1.0 :: Forms :: How do I validate a credit card number in ASP?


How do I validate a credit card number in ASP?

While with ASP alone you can't verify that a credit card belongs to this person, that it isn't stolen, that the credit is good or that the purchase price doesn't exceed the card's limit -- you can verify that it is a possible number (using a rough translation of Luhn / checksum) before bothering to waste transaction time with a true verification authority. 
 
<% 
    function isCreditCard(cardNo) 
 
        isCreditCard = false 
        lCard = len(cardNo) 
        lC = right(cardNo, 1) 
        cStat = 0 
        for i = (lCard - 1) to 1 step -1 
            tempChar = mid(cardNo, i, 1) 
            d = cint(tempChar) 
            if lcard mod 2 = 1 then 
                temp = d * (1 + ((i+1) mod 2)) 
            else 
                temp = d * (1 + (i mod 2)) 
            end if 
            if temp < 10 then 
                cStat = cStat + temp  
            else 
                cStat = cStat + temp - 9 
            end if 
        next 
        cStat = (10 - (cStat mod 10)) mod 10 
        if cint(lC) = cStat then isCreditCard = true 
    end function 
 
' test: 
 
    ' 4111111111111111 should pass (test number) 
    response.write("1:" & isCreditCard("4111111111111111") & "<br>") 
 
    ' 4111111111111112 should fail 
    response.write("2:" & isCreditCard("4111111111111112") & "<br>") 
%>
 
Most hosts will have credit card acceptance already set up for you. However, if you're doing it yourself, you're going to need a little bit more than a Luhn validation function. You will need an SSL certificate from Thawte or Verisign. For various reasons, I recommend Thawte. You will also need a secure place to store customer information. Keep in mind that you should try to avoid storing credit credit information if possible; the potential liability here is enormous. If you're going to store this information, you better have a well-guarded fort, and consider encrypting the number (see Article #2249 and Article #2397). 
 
You can look at these other vendors for credit card processing, either in component form or as a real-time service: 
 
    alphabetware 
 
    Authorize.net 
 
    Charge.com 
 
    Comersus 
 
    CyberStrong eShop 
 
    Ebanyan 
 
    effeng&amp;amp;amp;#252;d PayMate 
 
    E-Z Shop 
 
    IISCart 
 
    IP*Works 
 
    PDshopPro 
 
    PSiGate 
 
    Ustore Paypal 
 
    xAuthorize 
 
You can also see some of the shopping cart products listed in Article #2225. (Depending on capabilities, some vendors might be listed in both articles.)

Related Articles

How can I mimic a client-side POST from ASP?
How do I cause/prevent ENTER being used to submit a form?
How do I change the target frame or window of a response.redirect?
How do I disable certain FORM elements?
How do I disable IE's Autocomplete feature?
How do I iterate through a form collection?
How do I make form fields read-only?
How do I make one dropdown depend on another?
How do I pass x-y coordinates to ASP, after the user clicks an image?
How do I perform spell checking from a web page?
How do I retrieve the name of the form that was submitted?
How do I retrieve the text and the value from a <SELECT> element?
How do I submit forms to a new window, with window.open() features?
How do I upload files from the client to the server?
How do I validate forms using server side script?
What is the limit on Form / POST parameters?
What is the limit on QueryString / GET / URL parameters?
What is the size limit of a posted FORM field?
When I have multiple submit buttons, how do I tell which was clicked?
Which should I use: Request("item") or Request.Form("item")?
Why can't I access Request.Form() when uploading?
Why can't I pre-populate INPUT TYPE=FILE element?
Why do I get 'HTTP 405 - Resource Not Allowed' errors?
Why does my form variable become 'value, value' instead of 'value'?
Why does my input type=text value get truncated?
Why won't my <TEXTAREA> display the data I passed to it from ASP?

 

 


Created: 7/9/2000 | Last Updated: 12/9/2003 | broken links | helpful | not helpful | statistics
© Copyright 2006, UBR, Inc. All Rights Reserved. (277)

 

Copyright 1999-2006, All rights reserved.
Finding content
Finding content.  An error has occured...