asp tutorials, asp.net tutorials, sample code, and Microsoft news from 15Seconds
Data Access  |   Troubleshooting  |   Security  |   Performance  |   ADSI  |   Upload  |   Email  |   Control Building  |   Component Building  |   Forms  |   XML  |   Web Services  |   ASP.NET  |   .NET Features  |   .NET 2.0  |   App Development  |   App Architecture  |   IIS  |   Wireless
 
Pioneering Active Server
 Power Search





Active News
15 Seconds Weekly Newsletter
• Complete Coverage
• Site Updates
• Upcoming Features

More Free Newsletters
Reference
News
Articles
Code Samples
Components
Tools
New
Free
Downloads
Vendors
FAQ
Feedback
Books
Links
DL Archives
Community
Messageboard
List Servers
Mailing List
WebHosts
Consultants
Tech Jobs
15 Seconds
Home
Site Map
Press
Legal
Privacy Policy
internet.commerce














internet.com
IT
Developer
Internet News
Small Business
Personal Technology

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers

HardwareCentral
Compare products, prices, and stores at Hardware Central!

cctest.asp


<html>
<!-- Test Script for credit card information -->
<!-- (c) 1998 by Click Online -->
<!-- http://www.click-online.de -->
<!-- info@click-online.de -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<!-- #include file="checkcc.inc"-->
<title>Click Online Credit Card Test </title>
</head>

<body
<%
 response.write "text=""" & textcol1 &_
	 """ link=""" & textlink &_
	 """ vlink=""" & textvlink &_
	 """ alink=""" & textalink &_
	 """ background=""../images/" &_
	 bgimgurl & """ bgcolor=""" &_
	 bgcolor & """" %>>

<p><%number=request("number")
cctype=request("cctype")
if number<>"" then
  chk=checkcc(number,cctype)
  response.write "<br>Result: "
  select case chk
  case 0
    response.write "Card is ok!"
  case 1
    response.write "Wrong card type"
  case 2
    response.write "Wrong length"
  case 3
    response.write "Wrong length and card type"
  case 4 
    response.write "Wrong checksum"
  case 5 
    response.write "Wrong checksum and card type"
  case 6
    response.write "Wrong checksum and length"
  case 7
    response.write "Wrong checksum, length and card type"
  case 8
    response.write "unknown cardtype"
  end select
else
  response.write "Please enter a card number"
end if%></p>

<form method="POST">
  <p>Card number: <input type="text" name="number" size="20"
	value="<%=number%>"></p>
  <p>Type: <select name="cctype" size="1">
    <option value="V" <%if cctype="V" then response.write "selected"%>>
	VISA</option>
    <option value="M" <%if cctype="M" then response.write "selected"%>>
	Mastercard/Eurocard</option>
    <option value="A" <%if cctype="A" then response.write "selected"%>>
	American Express</option>
    <option value="C" <%if cctype="C" then response.write "selected"%>>
	Diners Club / Carte Blanche</option>
    <option value="D" <%if cctype="D" then response.write "selected"%>>
	Discover</option>
    <option value="E" <%if cctype="E" then response.write "selected"%>>
	enRoute</option>
    <option value="J" <%if cctype="J" then response.write "selected"%>>
	JCB</option>
    <option value="U" <%if cctype="U" then response.write "selected"%>>
	unknown cardtype (test)</option>
  </select></p>
  <p><input type="submit" value="Test it!" name="B1"></p>
</form>

<p>© 1998 by <a href="http://www.click-online.de">Click Online</a></p>
</body>
</html>


checkcc.inc



<%
' Credit Card check routine for ASP
' (c) 1998 by Click Online
' You may use these functions only if this header is not removed
' http://www.click-online.de
' info@click-online.de


function trimtodigits(tstring)
'removes all chars except of 0-9
  s="" 
  ts=tstring
  for x=1 to len(ts)
    ch=mid(ts,x,1)
    if asc(ch)>=48 and asc(ch)<=57 then
      s=s & ch
    end if
  next
  trimtodigits=s
end function

function checkcc(ccnumber,cctype)
  'checks credit card number for checksum,length and type
  'ccnumber= credit card number (all useless characters are
  '	being removed before check)
  '
  'cctype:
  '       "V" VISA
  '       "M" Mastercard/Eurocard
  '       "A" American Express
  '       "C" Diners Club / Carte Blanche
  '       "D" Discover
  '       "E" enRoute
  '       "J" JCB
  'returns:  checkcc=0 (Bit0)  : card valid
  '          checkcc=1 (Bit1) : wrong type
  '          checkcc=2 (Bit2) : wrong length
  '          checkcc=4 (Bit3) : wrong checksum (MOD10-Test)
  '          checkcc=8 (Bit4) : cardtype unknown
  '
  ctype=ucase(cctype)
  select case ctype
    case "V"
      cclength="13;16"
      ccprefix="4"
    case "M"
      cclength="16"
      ccprefix="51;52;53;54;55"
    case "A"
      cclength="15"
      ccprefix="34;37"
    case "C"
      cclength="14"
      ccprefix="300;301;302;303;304;305;36;38"
    case "D"
      cclength="16"
      ccprefix="6011"
    case "E"
      cclength="15"
      ccprefix="2014;2149"
    case "J"
      cclength="15;16"
      ccprefix="3;2131;1800"
    case else
      cclength=""
      ccprefix=""
  end select
  prefixes=split(ccprefix,";",-1)
  lengths=split(cclength,";",-1)
  number=trimtodigits(ccnumber)
  prefixvalid=false
  lengthvalid=false
  for each prefix in prefixes
    if instr(number,prefix)=1 then
      prefixvalid=true
    end if
  next  
  for each length in lengths
    if cstr(len(number))=length then
      lengthvalid=true
    end if
  next
  result=0
  if not prefixvalid then
    result=result+1
  end if  
  if not lengthvalid then
    result=result+2
  end if  
  qsum=0
  for x=1 to len(number)
    ch=mid(number,len(number)-x+1,1)
    'response.write ch
    if x mod 2=0 then
      sum=2*cint(ch)
      qsum=qsum+(sum mod 10)
      if sum>9 then 
        qsum=qsum+1
      end if
    else
      qsum=qsum+cint(ch)
    end if
  next
  'response.write qsum
  if qsum mod 10<>0 then
    result=result+4
  end if
  if cclength="" then
    result=result+8
  end if
  checkcc=result
end function
%>






email this code sample to a colleague

Related Products
AspCodeLock
ServerObjects Inc. announces AspCodeLock. This product will allow you to encrypt ASP script code at development time. AspCodeLock will dynamically decode the script when requested by IIS and execute it under the ASP environment. Your ASP code is processed in memory and is not written unencrypted to disk by AspCodeLock
[Top]



Support the Active Server Industry

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

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