spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / programming / carts / chap7 / 3 To page 1current pageTo page 3To page 4
[previous] [next]

Usable Shopping Carts, Chapter 7: CC Validation and Verification

Vice President of Risk Technology - READY TO HIRE! (NYC)
Next Step Systems
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


ASP (VBScript)

As mentioned previously, we will use a Luhn function to determine base level validity of the credit card number. This function doesn't determine if the credit card number actually exists, but rather that it could mathematically exist:

    Function CheckCCNumLuhn(ccnumber)

      Dim i, w, x, y

      y = 0

      ccnumber = Replace(Replace(Replace(CStr(ccnumber), "-", ""), " ", ""), ".", "")

Initially we accept the credit card number and then strip any extraneous information from the passed value.

      w = 2 * (Len(ccnumber) Mod 2)

      For i = Len(ccnumber) - 1 To 1 Step -1

        x = Mid(ccnumber, i, 1)

        if IsNumeric(x) Then

          Select Case (i Mod 2) + w

            Case 0, 3 

              y = y + CInt(x)

            Case 1, 2 

              x = CInt(x) * 2

              if x > 9 Then   

                y = y + (x \ 10) + (x - 10)

              Else

                y = y + x

              End if

          End Select

        End if

      Next     

To verify the number, it needs to be stepped through, from right to left and have a number of mathematic operations processed against it.

      y = 10 - (y Mod 10)

      if y > 9 Then y = 0

      CheckCC = (CStr(y) = Right(ccnumber, 1))

    End function

Finally we determine whether the integer value computed is equivalent to the final digit of the credit card number. If it is, then the function returns true. This indicates the number is a possible credit card number.


home / programming / carts / chap7 / 3 To page 1current pageTo page 3To page 4
[previous] [next]

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint

Created: January 2, 2003
Revised: January 2, 2003

URL: http://webreference.com/programming/carts/chap7/3/2.html