Ok, I need this script customized for my feildname's and to find out how to make it execute on button click.
Feild names :
cc_type = Card Type Selection
cc_number = Card Number
expdate_month = Card expiration Month
expdate_year = Card expiration Year
cc_vnumber = Card vercation number
==========================
==========
==========================
==========
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var Cards = new makeArray(8);
Cards[0] = new cc_type("MasterCard", "51,52,53,54,55", "16");
var MasterCard = Cards[0];
Cards[1] = new cc_type("VisaCard", "4", "13,16");
var VisaCard = Cards[1];
Cards[2] = new cc_type("AmExCard", "34,37", "15");
var AmExCard = Cards[2];
Cards[3] = new cc_type("DinersClubCard", "30,36,38", "14");
var DinersClubCard = Cards[3];
Cards[4] = new cc_type("DiscoverCard", "6011", "16");
var DiscoverCard = Cards[4];
Cards[5] = new cc_type("enRouteCard", "2014,2149", "15");
var enRouteCard = Cards[5];
Cards[6] = new cc_type("JCBCard", "3088,3096,3112,3158,3337,
3528", "16");
var JCBCard = Cards[6];
var LuhnCheckSum = Cards[7] = new cc_type();
function CheckCreditCard(Index,cc_n
umber,expd
ate_month,
expdate_ye
ar) {
var today = new Date()
var thisyear = today.getYear()
var thismonth = today.getMonth()+1
if ((eval(expdate_year) < thisyear)||((eval(expdate_
year)==thi
syear)&&(e
val(expdat
e_month)<t
hismonth))
) {
alert("This card has already expired.");
orders.elements[Index+2].f
ocus();
return false;
}
if (cc_number.length<13) {
alert("Please enter a valid credit card number.");
orders.elements[Index].foc
us();
return false;
}
if (!luhnCheck(cc_number)) {
alert("Please enter a valid credit card number.");
orders.elements[Index].foc
us();
return false;
}
}
/*************************
**********
**********
**********
**********
********\
Object cc_type([String cc_type, String rules, String len, int year,
int month])
cc_type : type of card, eg: MasterCard, Visa, etc.
rules : rules of the cc_number, eg: "4", "6011", "34,37".
len : valid length of cc_number, eg: "16,19", "13,16".
year : year of Expiration date.
month : month of Expiration date.
eg:
var VisaCard = new cc_type("Visa", "4", "16");
var AmExCard = new cc_type("AmEx", "34,37", "15");
\*************************
**********
**********
**********
**********
********/
function cc_type() {
var n;
var argv = cc_type.arguments;
var argc = cc_type.arguments.length;
this.objname = "object cc_type";
var tmpcc_type = (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";
this.setcc_number = setcc_number; // set cc_number method.
this.setcc_type = setcc_type; // setcc_type method.
this.setLen = setLen; // setLen method.
this.setRules = setRules; // setRules method.
this.setExpirationDate = setExpirationDate; // setExpirationDate method.
this.setcc_type(tmpcc_type
);
this.setLen(tmplen);
this.setRules(tmprules);
if (argc > 4)
this.setExpirationDate(arg
v[3], argv[4]);
this.checkcc_number = checkcc_number; // checkcc_number method.
this.getExpirationDate = getExpirationDate; // getExpirationDate method.
this.getcc_type = getcc_type; // getcc_type method.
this.iscc_number = iscc_number; // iscc_number method.
this.isExpirationDateValid
= isExpirationDateValid; // isExpirationDateValid method.
this.luhnCheck = luhnCheck;// luhnCheck method.
return this;
}
/*************************
**********
**********
**********
**********
********\
boolean checkcc_number([String cc_number, int year, int month])
return true if cc_number pass the luhncheck and the Expiration date is
valid, else return false.
\*************************
**********
**********
**********
**********
********/
function checkcc_number() {
var argv = checkcc_number.arguments;
var argc = checkcc_number.arguments.l
ength;
var cc_number = (argc > 0) ? argv[0] : this.cc_number;
var year = (argc > 1) ? argv[1] : this.year;
var month = (argc > 2) ? argv[2] : this.month;
this.setcc_number(cc_numbe
r);
this.setExpirationDate(yea
r, month);
if (!this.iscc_number())
return false;
if (!this.isExpirationDateVal
id())
return false;
return true;
}
/*************************
**********
**********
**********
**********
********\
String getcc_type()
return the cc_type.
\*************************
**********
**********
**********
**********
********/
function getcc_type() {
return this.cc_type;
}
/*************************
**********
**********
**********
**********
********\
String getExpirationDate()
return the Expiration date.
\*************************
**********
**********
**********
**********
********/
function getExpirationDate() {
return this.month + "/" + this.year;
}
/*************************
**********
**********
**********
**********
********\
boolean iscc_number([String cc_number])
return true if cc_number pass the luhncheck and the rules, else return
false.
\*************************
**********
**********
**********
**********
********/
function iscc_number() {
var argv = iscc_number.arguments;
var argc = iscc_number.arguments.leng
th;
var cc_number = (argc > 0) ? argv[0] : this.cc_number;
if (!this.luhnCheck())
return false;
for (var n = 0; n < this.len.size; n++)
if (cc_number.toString().leng
th == this.len[n]) {
for (var m = 0; m < this.rules.size; m++) {
var headdigit = cc_number.substring(0, this.rules[m].toString().l
ength);
if (headdigit == this.rules[m])
return true;
}
return false;
}
return false;
}
/*************************
**********
**********
**********
**********
********\
boolean isExpirationDateValid([int
year, int month])
return true if the date is a valid Expiration date,
else return false.
\*************************
**********
**********
**********
**********
********/
function isExpirationDateValid() {
var argv = isExpirationDateValid.argu
ments;
var argc = isExpirationDateValid.argu
ments.leng
th;
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();
Expiration = new Date(year, month);
alert(Expiration);
if (today.getTime() > Expiration.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 cc_number])
return true if cc_number 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 cc_number = argc > 0 ? argv[0] : this.cc_number;
if (! isNum(cc_number)) {
return false;
}
var no_digit = cc_number.length;
var oddoeven = no_digit & 1;
var sum = 0;
for (var count = 0; count < no_digit; count++) {
var digit = parseInt(cc_number.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;
}
/*************************
**********
**********
**********
**********
********\
cc_type setcc_number(cc_number)
return the cc_type object.
\*************************
**********
**********
**********
**********
********/
function setcc_number(cc_number) {
this.cc_number = cc_number;
return this;
}
/*************************
**********
**********
**********
**********
********\
cc_type setcc_type(cc_type)
return the cc_type object.
\*************************
**********
**********
**********
**********
********/
function setcc_type(cc_type) {
this.cc_type = cc_type;
return this;
}
/*************************
**********
**********
**********
**********
********\
cc_type setExpirationDate(expdate_
year, expdate_month)
return the cc_type object.
\*************************
**********
**********
**********
**********
********/
function setExpirationDate(expdate_
year, expdate_month) {
this.year = expdate_year;
this.month = expdate_month;
return this;
}
/*************************
**********
**********
**********
**********
********\
cc_type setLen(len)
return the cc_type 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.in
dexOf(",")
+ 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;
}
/*************************
**********
**********
**********
**********
********\
cc_type setRules()
return the cc_type 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(tmprule
s.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.inde
xOf(",") + 1, rules.length);
n++;
}
this.rules[n] = rules;
return this;
}
// End -->
</script>
Start Free Trial