Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Credit Card and Expiry validation

Posted on 1998-09-11
Medium Priority
646 Views
Does anyone have a credit card validation javascript function?
0
Question by:hamishd
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• Learn & ask questions

LVL 10

Accepted Solution

MasseyM earned 200 total points
ID: 1270718
Here you go... Here are three that I found:
---------------------------------------------------
<!--Beginning of the script-->
<SCRIPT LANGUAGE="JavaScript">
<!--
function MakeArray(n)
{
this.length = n;
for (var i = 1; i <= n; i++)
{this[i] = 0;}
return this;
}

function error(outputform,cname)
{
if(cname=="visa")
outputform.result.value="Error: The valid length for Visa is 13 or 16 digits!";

if(cname=="novus")
outputform.result.value="Error: The valid length for Novus is 16 digits!";

if(cname=="amex")
outputform.result.value="Error: The valid length for American Express is 15 digits!";

if(cname=="mastercard")
outputform.result.value="Error: The valid length for MasterCard is 16 digits!";
}

//IMPORTANT: Array is indexed from 1, charAt form 0

function check(inputform, outputform) {
//Array of digits
cc = new MakeArray(30);
//Card name, number of digits, corresponding staring value;
var cname="",nlength=0,start=0;
//Temp variables
var t0,t1,tmp;

//Get Card Name
for( i=0; i<inputform.card.length; i++ )
if(inputform.card[i].checked)
{cname=inputform.card[i].value; break;}

//Restore credit card number
for (var i =1; i<=inputform.cn.value.length; i++)
{
t0=(parseInt(inputform.cn.value.charAt(i-1),10)).toString();
if(t0 != "NaN")
cc[++nlength]=parseInt(inputform.cn.value.charAt(i-1),10);
}

//Check length for the name
if(cname=="visa" && nlength!=13 && nlength!=16)
{ error(outputform,cname); return; }

if(cname=="novus" && nlength!=16)
{ error(outputform,cname); return; }

if(cname=="amex" && nlength!=15)
{ error(outputform,cname); return; }

if(cname=="mastercard" && nlength!=16)
{ error(outputform,cname); return; }

if(nlength==13)
start=2;
if(nlength==15)
start=2;
if(nlength==16)
start=1;

//-------------------Main routine----------------
for (var i=start; i<=nlength; i+=2)
{
tmp=cc[i]*2;
if(tmp >= 10)
{
t0=parseInt(tmp.toString().charAt(0),10);
t1=parseInt(tmp.toString().charAt(1),10);
cc[i]=t0+t1;
}
else
cc[i]=tmp;
}

tmp=0;
for (var i =1; i <= nlength; i++)
tmp+=cc[i];

//inputform.inter.value=tmp;

if(parseInt(tmp.toString().charAt(1),10)!=0)
outputform.result.value="Invalid Number";
else
outputform.result.value="Valid Number";
}
//-->
</SCRIPT>
<!--End of the script-->

<SCRIPT LANGUAGE="JavaScript">
<!--
function LastModifiedDate(str)
{
resdate=new Date(str.substring(6,8),eval(str.substring(0,2))-1,str.substring(3,5),str.substring(9,11),str.substring(12,14),str.substring(15,17));
return (resdate.toString());
}created="April 14, 1997";
//-->
</SCRIPT>

-------------------------------------------------------
<script language="javascript">
/*************************************************************************\
Author: Simon Tneoh Chee-Boon
Permission to use, copy, modify, and distribute this software and its
documentation for commercial or non-commercial purposes is hereby granted
provided that this copyright notice appears in all copies.
This is a demonstration of using credit card javascript object. The
credit cards used here are the international standard card. Luhncheck is
used to validate the card number.
\*************************************************************************/
var Cards = new makeArray(8);
Cards[0] = new CardType("MasterCard", "51,52,53,54,55", "16");
var MasterCard = Cards[0];
Cards[1] = new CardType("VisaCard", "4", "13,16");
var VisaCard = Cards[1];
Cards[2] = new CardType("AmExCard", "34,37", "15");
var AmExCard = Cards[2];
Cards[3] = new CardType("DinersClubCard", "30,36,38", "14");
var DinersClubCard = Cards[3];
Cards[4] = new CardType("DiscoverCard", "6011", "16");
var DiscoverCard = Cards[4];
Cards[5] = new CardType("enRouteCard", "2014,2149", "15");
var enRouteCard = Cards[5];
Cards[6] = new CardType("JCBCard", "3088,3096,3112,3158,3337,3528", "16");
var JCBCard = Cards[6];
var LuhnCheckSum = Cards[7] = new CardType();

/*************************************************************************\
CheckCardNumber(form)
function called when users click the "check" button.
\*************************************************************************/
function CheckCardNumber(form) {
var tmpyear;
if (form.CardNumber.value.length == 0) {
form.CardNumber.focus();
return;
}
if (form.ExpYear.value.length == 0) {
form.ExpYear.focus();
return;
}
if (form.ExpYear.value > 96)
tmpyear = "19" + form.ExpYear.value;
else if (form.ExpYear.value < 21)
tmpyear = "20" + form.ExpYear.value;
else {
return;
}
tmpmonth = form.ExpMon.options[form.ExpMon.selectedIndex].value;
// The following line doesn't work in IE3, you need to change it
// to something like "(new CardType())...".
// if (!CardType().isExpiryDate(tmpyear, tmpmonth)) {
if (!(new CardType()).isExpiryDate(tmpyear, tmpmonth)) {
return;
}
card = form.CardType.options[form.CardType.selectedIndex].value;
var retval = eval(card + ".checkCardNumber(\"" + form.CardNumber.value +
"\", " + tmpyear + ", " + tmpmonth + ");");

cardname = "";
if (retval)
// The cardnumber has the valid luhn checksum and matches the
// cardtype's rule.
else {
// The cardnumber has the valid luhn checksum, but we want to know which
// cardtype it belongs to.
for (var n = 0; n < Cards.size; n++) {
if (Cards[n].checkCardNumber(form.CardNumber.value, tmpyear, tmpmonth)) {
cardname = Cards[n].getCardType();
break;
}
}
if (cardname.length > 0) {
alert("This's " + cardname + " number, not " + card + " number.");
}
else {
alert("This's not a card number.");
}
}
}

/*************************************************************************\
Object CardType([String cardtype, String rules, String len, int year,
int month])
cardtype    : type of card, eg: MasterCard, Visa, etc.
rules       : rules of the cardnumber, eg: "4", "6011", "34,37".
len         : valid length of cardnumber, eg: "16,19", "13,16".
year      : year of expiry date.
month      : month of expiry date.
eg:
var VisaCard = new CardType("Visa", "4", "16");
var AmExCard = new CardType("AmEx", "34,37", "15");
\*************************************************************************/
function CardType() {
var n;
var argv = CardType.arguments;
var argc = CardType.arguments.length;

this.objname = "object CardType";

var tmpcardtype = (argc > 0) ? argv[0] : "CardObject";
var tmprules = (argc > 1) ? argv[1] : "0,1,2,3,4,5,6,7,8,9";
var tmplen = (argc > 2) ? argv[2] : "13,14,15,16,19";

// set CardNumber method.
this.setCardNumber = setCardNumber;

// setCardType method.
this.setCardType = setCardType;

// setLen method.
this.setLen = setLen;

// setRules method.
this.setRules = setRules;

// setExpiryDate method.
this.setExpiryDate = setExpiryDate;

this.setCardType(tmpcardtype);
this.setLen(tmplen);
this.setRules(tmprules);
if (argc > 4)
this.setExpiryDate(argv[3], argv[4]);

// checkCardNumber method.
this.checkCardNumber = checkCardNumber;

// getExpiryDate method.
this.getExpiryDate = getExpiryDate;

// getCardType method.
this.getCardType = getCardType;

// isCardNumber method.
this.isCardNumber = isCardNumber;

// isExpiryDate method.
this.isExpiryDate = isExpiryDate;

// luhnCheck method.
this.luhnCheck = luhnCheck;

return this;
}

/*************************************************************************\
boolean checkCardNumber([String cardnumber, int year, int month])
return true if cardnumber pass the luhncheck and the expiry date is
valid, else return false.
\*************************************************************************/
function checkCardNumber() {
var argv = checkCardNumber.arguments;
var argc = checkCardNumber.arguments.length;
var cardnumber = (argc > 0) ? argv[0] : this.cardnumber;
var year = (argc > 1) ? argv[1] : this.year;
var month = (argc > 2) ? argv[2] : this.month;

this.setCardNumber(cardnumber);
this.setExpiryDate(year, month);

if (!this.isCardNumber())
return false;

if (!this.isExpiryDate())
return false;

return true;
}

/*************************************************************************\
String getCardType()
return the cardtype.
\*************************************************************************/
function getCardType() {
return this.cardtype;
}

/*************************************************************************\
String getExpiryDate()
return the expiry date.
\*************************************************************************/
function getExpiryDate() {
return this.month + "/" + this.year;
}

/*************************************************************************\
boolean isCardNumber([String cardnumber])
return true if cardnumber pass the luhncheck and the rules, else return
false.
\*************************************************************************/
function isCardNumber() {
var argv = isCardNumber.arguments;
var argc = isCardNumber.arguments.length;
var cardnumber = (argc > 0) ? argv[0] : this.cardnumber;

if (!this.luhnCheck())
return false;

for (var n = 0; n < this.len.size; n++)
if (cardnumber.toString().length == this.len[n]) {
for (var m = 0; m < this.rules.size; m++) {
var headdigit = cardnumber.substring(0, this.rules[m].toString().length);
if (headdigit == this.rules[m])
return true;
}
return false;
}

return false;
}

/*************************************************************************\
boolean isExpiryDate([int year, int month])
return true if the date is a valid expiry date,
else return false.
\*************************************************************************/
function isExpiryDate() {
var argv = isExpiryDate.arguments;
var argc = isExpiryDate.arguments.length;

year = argc > 0 ? argv[0] : this.year;
month = argc > 1 ? argv[1] : this.month;

if (!isNum(year+""))
return false;
if (!isNum(month+""))
return false;
today = new Date();
expiry = new Date(year, month);
if (today.getTime() > expiry.getTime())
return false;
else
return true;
}

/*************************************************************************\
boolean isNum(String argvalue)
return true if argvalue contains only numeric characters,
else return false.
\*************************************************************************/
function isNum(argvalue) {
argvalue = argvalue.toString();

if (argvalue.length == 0)
return false;

for (var n = 0; n < argvalue.length; n++)
if (argvalue.substring(n, n+1) < "0" || argvalue.substring(n, n+1) > "9")
return false;

return true;
}

/*************************************************************************\
boolean luhnCheck([String CardNumber])
return true if CardNumber pass the luhn check else return false.
Reference: http://www.ling.nwu.edu/~sburke/pub/luhn_lib.pl
\*************************************************************************/
function luhnCheck() {
var argv = luhnCheck.arguments;
var argc = luhnCheck.arguments.length;

var CardNumber = argc > 0 ? argv[0] : this.cardnumber;

if (! isNum(CardNumber)) {
return false;
}

var no_digit = CardNumber.length;
var oddoeven = no_digit & 1;
var sum = 0;

for (var count = 0; count < no_digit; count++) {
var digit = parseInt(CardNumber.charAt(count));
if (!((count & 1) ^ oddoeven)) {
digit *= 2;
if (digit > 9)
digit -= 9;
}
sum += digit;
}
if (sum % 10 == 0)
return true;
else
return false;
}

/*************************************************************************\
ArrayObject makeArray(int size)
return the array object in the size specified.
\*************************************************************************/
function makeArray(size) {
this.size = size;
return this;
}

/*************************************************************************\
CardType setCardNumber(cardnumber)
return the CardType object.
\*************************************************************************/
function setCardNumber(cardnumber) {
this.cardnumber = cardnumber;

return this;
}

/*************************************************************************\
CardType setCardType(cardtype)
return the CardType object.
\*************************************************************************/
function setCardType(cardtype) {
this.cardtype = cardtype;

return this;
}

/*************************************************************************\
CardType setExpiryDate(year, month)
return the CardType object.
\*************************************************************************/
function setExpiryDate(year, month) {
this.year = year;
this.month = month;

return this;
}

/*************************************************************************\
CardType setLen(len)
return the CardType object.
\*************************************************************************/
function setLen(len) {
// Create the len array.
if (len.length == 0 || len == null)
len = "13,14,15,16,19";

var tmplen = len;
n = 1;
while (tmplen.indexOf(",") != -1) {
tmplen = tmplen.substring(tmplen.indexOf(",") + 1, tmplen.length);
n++;
}
this.len = new makeArray(n);
n = 0;
while (len.indexOf(",") != -1) {
var tmpstr = len.substring(0, len.indexOf(","));
this.len[n] = tmpstr;
len = len.substring(len.indexOf(",") + 1, len.length);
n++;
}
this.len[n] = len;

return this;
}

/*************************************************************************\
CardType setRules()
return the CardType object.
\*************************************************************************/
function setRules(rules) {
// Create the rules array.
if (rules.length == 0 || rules == null)
rules = "0,1,2,3,4,5,6,7,8,9";

var tmprules = rules;
n = 1;
while (tmprules.indexOf(",") != -1) {
tmprules = tmprules.substring(tmprules.indexOf(",") + 1, tmprules.length);
n++;
}
this.rules = new makeArray(n);
n = 0;
while (rules.indexOf(",") != -1) {
var tmpstr = rules.substring(0, rules.indexOf(","));
this.rules[n] = tmpstr;
rules = rules.substring(rules.indexOf(",") + 1, rules.length);
n++;
}
this.rules[n] = rules;

return this;
}

</script>
<body bgcolor="#ffffff">
<h2>Credit Card Number Validator</h2>
<hr>
<blockquote>
Please do not use a real card number and valid expiry date to test. If you
really want to do it, please check the source first, make sure it will not
submit the card number.<br></font>
<form name="ThisForm">
Card Number: <input name="CardNumber" size="16" maxlength="19"><br>
Card Type:
<select name="CardType">
<option value="MasterCard">MasterCard
<option value="VisaCard">Visa
<option value="AmExCard">AmEx
<option value="DinersClubCard">Diners Club
<option value="DiscoverCard">Discover
<option value="enRouteCard">enRoute
<option value="JCBCard">JCB
<option value="LuhnCheckSum">luhn check only
</select>
<br>
Expiry Date: Month
<select name="ExpMon">
<option value="1" selected>1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
<option value="6">6
<option value="7">7
<option value="8">8
<option value="9">9
<option value="10">10
<option value="11">11
<option value="12">12
</select>
Year <input name="ExpYear" size="2" maxlength="2">(Range: 1997~2020)<br>
<input type="button" value="Check" OnClick="CheckCardNumber(this.form)"><br>
</form>
---------------------------------------------------------------

<!--
Copyright 1997 David Turley <dturley@pobox.com>
This Javascript may be modified and used by anyone as long as this notice
remains intact. You may not sell or otherwise profit from this code without
my permission.

This code is based on CC-Verify, a Perl script
by Dave Paris (aka Spider)
The Perl code is available at
http://worldwidemart.com/scripts/ccver.shtml
-->

<SCRIPT>

function checkcc(){

failed=false
Str=document.cc.number.value
newStr=''
card=''

month_index = document.cc.exp_month.selectedIndex
exp_month = document.cc.exp_month.options[month_index].text

year_index = document.cc.exp_year.selectedIndex
exp_year = document.cc.exp_year.options[year_index].text

d=new Date()
cur_month = d.getMonth() + 1
cur_year = d.getYear() + 1900

//get card type
if(document.cc[0].checked){card="master"}
if(document.cc[1].checked){card="visa"}
if(document.cc[2].checked){card="amex"}

if (card=='') {
error("You did not choose a card type")
return
}

//check the expiration date
if (exp_year < cur_year) {
error("Your card has expired")
return
}

if ((exp_year == cur_year) && (exp_month < cur_month)) {
error("Your card has expired")
return
}

//remove spaces and dashes
for (var k = 0; k < Str.length; k++){
var oneChar = Str.charAt(k)
if ((oneChar != " ") && (oneChar != "-")) {
newStr += Str.charAt(k)

}
}

//check for digits only

for (var k = 0; k < newStr.length; k++){
var oneChar = newStr.charAt(k)
if (oneChar < "0" || oneChar > "9") {
error("Invalid characters in number.")
return

}

}

//check length for card type

if(card == "visa"){
if((newStr.length != "13") && (newStr.length != "16")){
error("Incorrect number of digits.")
return
}

}

if(card == "master"){
if(newStr.length != "16"){
error("Incorrect number of digits.")
return
}

}

if(card == "amex"){
if(newStr.length != "15"){
error("Incorrect number of digits.")
return
}

}

//verify Mod 10

if(newStr.length == "13"){len13()}
if(newStr.length == "15"){len15()}
if(newStr.length == "16"){len16()}

// if all tests passed
if (!failed){
//whatever redirection is necessary goes here
alert("The credit card number is valid.")

}

}//end of checkcc function

function len13(){
cc0 = newStr.charAt(0)
cc1 = newStr.charAt(1)
cc2 = newStr.charAt(2)
cc3 = newStr.charAt(3)
cc4 = newStr.charAt(4)
cc5 = newStr.charAt(5)
cc6 = newStr.charAt(6)
cc7 = newStr.charAt(7)
cc8 = newStr.charAt(8)
cc9 = newStr.charAt(9)
cc10 = newStr.charAt(10)
cc11 = newStr.charAt(11)
cc12 = newStr.charAt(12)

cc1a = cc1 * 2
cc3a = cc3 * 2
cc5a = cc5 * 2
cc7a = cc7 * 2
cc9a = cc9 * 2
cc11a = cc11 * 2

if(cc1a >= 10) {
cc1a=cc1a.toString()
cc1b = cc1a.charAt(0)
cc1c = cc1a.charAt(1)
cc1 = parseFloat(cc1b) + parseFloat(cc1c)
}
else {
cc1 = cc1a
}

if(cc3a >= 10) {

cc3a=cc3a.toString()
cc3b = cc3a.charAt(0)
cc3c = cc3a.charAt(1)
cc3 = parseFloat(cc3b) + parseFloat(cc3c)

}

else {
cc3 = cc3a
}

if (cc5a >= 10) {
cc5a=cc5a.toString()
cc5b = cc5a.charAt(0)
cc5c = cc5a.charAt(1)
cc5 = parseFloat(cc5b) + parseFloat(cc5c)

}

else {
cc5 = cc5a
}

if (cc7a >= 10) {
cc7a=cc7a.toString()
cc7b = cc7a.charAt(0)
cc7c = cc7a.charAt(1)
cc7 = parseFloat(cc7b) + parseFloat(cc7c)
}

else {
cc7 = cc7a
}

if (cc9a >= 10) {
cc9a=cc9a.toString()
cc9b = cc9a.charAt(0)
cc9c = cc9a.charAt(1)
cc9 = parseFloat(cc9b) + parseFloat(cc9c)
}

else {
cc9 = cc9a
}

if (cc11a >= 10) {
cc11a=cc11a.toString()
cc11b = cc11a.charAt(0)
cc11c = cc11a.charAt(1)
cc11 = parseFloat(cc11b) + parseFloat(cc11c)
}

else {
cc11 = cc11a
}

value = 0
value +=parseFloat(cc0)
value +=parseFloat(cc1)
value +=parseFloat(cc2)
value +=parseFloat(cc3)
value +=parseFloat(cc4)
value +=parseFloat(cc5)
value +=parseFloat(cc6)
value +=parseFloat(cc7)
value +=parseFloat(cc8)
value +=parseFloat(cc9)
value +=parseFloat(cc10)
value +=parseFloat(cc11)
value +=parseFloat(cc12)

value=value.toString()

if (value.charAt(1) != 0){

error("Invalid card number.")
return
}

}

function len15(){
cc0 = newStr.charAt(0)
cc1 = newStr.charAt(1)
cc2 = newStr.charAt(2)
cc3 = newStr.charAt(3)
cc4 = newStr.charAt(4)
cc5 = newStr.charAt(5)
cc6 = newStr.charAt(6)
cc7 = newStr.charAt(7)
cc8 = newStr.charAt(8)
cc9 = newStr.charAt(9)
cc10 = newStr.charAt(10)
cc11 = newStr.charAt(11)
cc12 = newStr.charAt(12)
cc13 = newStr.charAt(13)
cc14 = newStr.charAt(14)

cc1a = cc1 * 2
cc3a = cc3 * 2
cc5a = cc5 * 2
cc7a = cc7 * 2
cc9a = cc9 * 2
cc11a = cc11 * 2
cc13a = cc13 * 2

if(cc1a >= 10) {
cc1a=cc1a.toString()
cc1b = cc1a.charAt(0)
cc1c = cc1a.charAt(1)
cc1 = parseFloat(cc1b) + parseFloat(cc1c)
}
else {
cc1 = cc1a
}

if(cc3a >= 10) {

cc3a=cc3a.toString()
cc3b = cc3a.charAt(0)
cc3c = cc3a.charAt(1)
cc3 = parseFloat(cc3b) + parseFloat(cc3c)
}

else {
cc3 = cc3a
}

if (cc5a >= 10) {
cc5a=cc5a.toString()
cc5b = cc5a.charAt(0)
cc5c = cc5a.charAt(1)
cc5 = parseFloat(cc5b) + parseFloat(cc5c)
}

else {
cc5 = cc5a
}

if (cc7a >= 10) {
cc7a=cc7a.toString()
cc7b = cc7a.charAt(0)
cc7c = cc7a.charAt(1)
cc7 = parseFloat(cc7b) + parseFloat(cc7c)
}

else {
cc7 = cc7a
}

if (cc9a >= 10){
cc9a=cc9a.toString()
cc9b = cc9a.charAt(0)
cc9c = cc9a.charAt(1)
cc9 = parseFloat(cc9b) + parseFloat(cc9c)
}

else {
cc9 = cc9a
}

if (cc11a >= 10) {
cc11a=cc11a.toString()
cc11b = cc11a.charAt(0)
cc11c = cc11a.charAt(1)
cc11 = parseFloat(cc11b) + parseFloat(cc11c)
}

else {
cc11 = cc11a
}

if (cc13a >= 10) {
cc13a=cc13a.toString()
cc13b = cc13a.charAt(0)
cc13c = cc13a.charAt(1)
cc13 = parseFloat(cc13b) + parseFloat(cc13c)
}

else {
cc13 = cc13a
}

value = 0
value +=parseFloat(cc0)
value +=parseFloat(cc1)
value +=parseFloat(cc2)
value +=parseFloat(cc3)
value +=parseFloat(cc4)
value +=parseFloat(cc5)
value +=parseFloat(cc6)
value +=parseFloat(cc7)
value +=parseFloat(cc8)
value +=parseFloat(cc9)
value +=parseFloat(cc10)
value +=parseFloat(cc11)
value +=parseFloat(cc12)
value +=parseFloat(cc13)
value +=parseFloat(cc14)

value=value.toString()

if (value.charAt(1) != 0) {

error("Invalid card number.")
return
}
}

function len16() {
cc0 = newStr.charAt(0)
cc1 = newStr.charAt(1)
cc2 = newStr.charAt(2)
cc3 = newStr.charAt(3)
cc4 = newStr.charAt(4)
cc5 = newStr.charAt(5)
cc6 = newStr.charAt(6)
cc7 = newStr.charAt(7)
cc8 = newStr.charAt(8)
cc9 = newStr.charAt(9)
cc10 = newStr.charAt(10)
cc11 = newStr.charAt(11)
cc12 = newStr.charAt(12)
cc13 = newStr.charAt(13)
cc14 = newStr.charAt(14)
cc15 = newStr.charAt(15)

cc0a = cc0 * 2
cc2a = cc2 * 2
cc4a = cc4 * 2
cc6a = cc6 * 2
cc8a = cc8 * 2
cc10a = cc10 * 2
cc12a = cc12 * 2
cc14a = cc14 * 2

if(cc0a >= 10) {
cc0a=cc0a.toString()
cc0b = cc0a.charAt(0)
cc0c = cc0a.charAt(1)
cc0 = parseFloat(cc0b) + parseFloat(cc0c)
}
else {
cc0 = cc0a
}

if(cc2a >= 10) {

cc2a=cc2a.toString()
cc2b = cc2a.charAt(0)
cc2c = cc2a.charAt(1)
cc2 = parseFloat(cc2b) + parseFloat(cc2c)
}

else {
cc2 = cc2a
}

if (cc4a >= 10) {
cc4a=cc4a.toString()
cc4b = cc4a.charAt(0)
cc4c = cc4a.charAt(1)
cc4 = parseFloat(cc4b) + parseFloat(cc4c)
}

else {
cc4 = cc4a
}

if (cc6a >= 10) {
cc6a=cc6a.toString()
cc6b = cc6a.charAt(0)
cc6c = cc6a.charAt(1)
cc6 = parseFloat(cc6b) + parseFloat(cc6c)
}

else {
cc6 = cc6a
}

if (cc8a >= 10) {
cc8a=cc8a.toString()
cc8b = cc8a.charAt(0)
cc8c = cc8a.charAt(1)
cc8 = parseFloat(cc8b) + parseFloat(cc8c)
}

else {
cc8 = cc8a
}

if (cc10a >= 10) {
cc10a=cc10a.toString()
cc10b = cc10a.charAt(0)
cc10c = cc10a.charAt(1)
cc10 = parseFloat(cc10b) + parseFloat(cc10c)
}

else {
cc10 = cc10a
}

if (cc12a >= 10) {
cc12a=cc12a.toString()
cc12b = cc12a.charAt(0)
cc12c = cc12a.charAt(1)
cc12 = parseFloat(cc12b) + parseFloat(cc12c)
}

else {
cc12 = cc12a
}

if (cc14a >= 10) {
cc14a=cc14a.toString()
cc14b = cc14a.charAt(0)
cc14c = cc14a.charAt(1)
cc14 = parseFloat(cc14b) + parseFloat(cc14c)
}

else {
cc14 = cc14a
}

value = 0
value +=parseFloat(cc0)
value +=parseFloat(cc1)
value +=parseFloat(cc2)
value +=parseFloat(cc3)
value +=parseFloat(cc4)
value +=parseFloat(cc5)
value +=parseFloat(cc6)
value +=parseFloat(cc7)
value +=parseFloat(cc8)
value +=parseFloat(cc9)
value +=parseFloat(cc10)
value +=parseFloat(cc11)
value +=parseFloat(cc12)
value +=parseFloat(cc13)
value +=parseFloat(cc14)
value +=parseFloat(cc15)

value=value.toString()

if (value.charAt(1) != 0) {

error("Invalid card number.")
return
}

}

function error(msg) {
failed=true
}

</SCRIPT>
<BODY BGCOLOR="#FFFFFF">

<H2 ALIGN=center>Credit Card Number Verification</H2>
<HR>

This script can be used to verify the validity of a credit card number before it is uploaded to the server. It validates numbers for cards that use a Mod 10 algorithm.<P>
JavaScript by <A HREF="mailto:dturley@pobox.com">David Turley</A><HR><P>

<FORM NAME=cc>
<TABLE><TR VALIGN=top><TD>

Choose a credit card type:</TD><TD>
<INPUT TYPE="radio" NAME="type" VALUE="master" onClick=0>Mastercard<BR>
<INPUT TYPE="radio" NAME="type" VALUE="visa" onClick=0>VISA<BR>
<INPUT TYPE="radio" NAME="type" VALUE="amex" onClick=0>American Express
</TD></TR>

<TR VALIGN=top><TD>
Enter a number:</TD><TD>
<INPUT TYPE="text" SIZE=25 NAME=number><P>
</TD></TR>

<TR VALIGN=top><TD>
Enter expiration date: Month
<SELECT NAME="exp_month">
<OPTION VALUE="01"> 01
<OPTION VALUE="02"> 02
<OPTION VALUE="03"> 03
<OPTION VALUE="04"> 04
<OPTION VALUE="05"> 05
<OPTION VALUE="06"> 06
<OPTION VALUE="07"> 07
<OPTION VALUE="08"> 08
<OPTION VALUE="09"> 09
<OPTION VALUE="10"> 10
<OPTION VALUE="11"> 11
<OPTION VALUE="12"> 12
</SELECT></TD><TD>Year

<SELECT NAME="exp_year">
<OPTION VALUE="1997"> 1997
<OPTION VALUE="1998"> 1998
<OPTION VALUE="1999"> 1999
<OPTION VALUE="2000"> 2000
<OPTION VALUE="2001"> 2001
</SELECT>
</TD></TR>

</TABLE>
<INPUT TYPE="button" VALUE="CHECK" onClick="checkcc()">
<INPUT TYPE="reset"
VALUE="CLEAR">

</FORM>

0

Author Comment

ID: 1270719
Thank you
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Learn about the eCommerce marketing trends for the year ahead.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
###### Suggested Courses
Course of the Month5 days, 9 hours left to enroll

#### 660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.