|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
Validation Using the Luhn AlgorithmThe algorithm used to validate the credit card number is known as the Luhn Algorithm, and it employs the following steps:
The total found by following the preceding steps must be divisible by 10 (must end in 0) for it to be a well-formed credit card number. Example: Total = 68. This number is not well formed. If the original number in the preceding example had been
the total would have worked out to be 60, and it would be well formed. This number would not have passed the complete well-formed test, however, because its prefix and length do not match any of the major credit cards shown in Table 21.1. If you are planning on using JavaScript functions to verify that credit card numbers are well formed, you should have a set of sample numbers to use to verify that the functions are working correctly. (It is not a good idea to test these functions by using your own credit card numbers unless you are sure their information wont be accessible over the Web.) Table 21.2 shows a set of sample well-formed credit card numbers, available from the Netscape Web site. (The next section of this chapter discusses this Netscape site in more detail.)
A number of freely available JavaScripts implement the test for a well-formed credit card number. You can find one of them, developed by Simon Tneoh, at the following URL: http://www.tneoh.zoneit.com/javascript/cardobject.html
Listing 21.8 ChkCard.htm Checking for Well-Formed Credit Card Numbers Can Be the First Step in Validating Them; You Still Need to Verify Them on the Server <HTML> <HEAD> <TITLE>Check for Well-Formed Credit Card Number</TITLE> <SCRIPT LANGUAGE="JAVASCRIPT" src="ChkCard.js"></SCRIPT> </HEAD> <BODY BGCOLOR=#FFFFFF> <CENTER> <H1>Check for Well-Formed Credit Card Number</H1> <HR> </CENTER> <FONT COLOR=#FF0000>Alert! Please do not use a real card number and valid expiration date to test. If you really want to do it, please check the source first, make sure it will not submit the card number. </FONT> <CENTER> <TABLE> <FORM NAME="MyForm"> <TR><TD>Card Number:</TD> <TD><INPUT TYPE=TEXT NAME="CardNumber" SIZE=16 MAXLENGTH=19></TD></TR> <TR><TD>Card Type:</TD> <TD><SELECT NAME="CardType"> <OPTION VALUE="MasterCard">MasterCard <OPTION VALUE="VisaCard">Visa <OPTION VALUE="AmExCard">American Express <OPTION VALUE="DinersClubCard">Diners Club <OPTION VALUE="DiscoverCard">Discover <OPTION VALUE="enRouteCard">enRoute <OPTION VALUE="JCBCard">JCB <OPTION VALUE="LuhnCheckSum">Luhn Check Only </SELECT></TD></TR> <TR><TD>Expiration Month:</TD> <TD><SELECT NAME="ExpMon"> <OPTION VALUE=01>January <OPTION VALUE=02>February <OPTION VALUE=03>March <OPTION VALUE=04>April <OPTION VALUE=05>May <OPTION VALUE=06>June <OPTION VALUE=07>July <OPTION VALUE=08>August <OPTION VALUE=09>Septembet <OPTION VALUE=10>October <OPTION VALUE=11>November <OPTION VALUE=12 SELECTED>December </SELECT></TD></TR> <TR><TD>Expiration Year:</TD> <TD><SELECT NAME="ExpYear"> <OPTION VALUE=97 selected>1997 <OPTION VALUE=98>1998 <OPTION VALUE=99>1999 <OPTION VALUE=00>2000 <OPTION VALUE=01>2001 <OPTION VALUE=02>2002 </SELECT></TD></TR> <TR><TD>&nbsp;</TD> <TD><INPUT TYPE=BUTTON VALUE="Check" OnClick="CheckCardNumber(document.MyForm)"></TD></TR> </FORM> </TABLE> <HR> </CENTER> <ADDRESS> Jim ODonnell, <A HREF="mailto:odonnj@rpi.edu">odonnj@rpi.edu</A> </ADDRESS> </BODY> </HTML>
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |