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

Technical Lead
Thomson Reuters (Markets) LLC
US-NY-New York

Justtechjobs.com Post A Job | Post A Resume
Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?


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, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business

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

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