Advertisement

10.06.2004 at 09:37AM PDT, ID: 21158218
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

6.0

URGENT ::: I need help making my credit card vaildator to work... its javascript --500points

Asked by Caiapfas in Miscellaneous Web Development, E-Commerce

Tags: , , ,

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_number,expdate_month,expdate_year) {
var today = new Date()
var thisyear = today.getYear()
var thismonth = today.getMonth()+1

if ((eval(expdate_year) < thisyear)||((eval(expdate_year)==thisyear)&&(eval(expdate_month)<thismonth))) {
alert("This card has already expired.");
orders.elements[Index+2].focus();
return false;
}


if (cc_number.length<13) {
alert("Please enter a valid credit card number.");
orders.elements[Index].focus();
return false;
}


if (!luhnCheck(cc_number)) {
alert("Please enter a valid credit card number.");
orders.elements[Index].focus();
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(argv[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.length;
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_number);
this.setExpirationDate(year, month);

if (!this.iscc_number())
return false;
if (!this.isExpirationDateValid())
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.length;
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().length == this.len[n]) {
for (var m = 0; m < this.rules.size; m++) {
var headdigit = cc_number.substring(0, this.rules[m].toString().length);
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.arguments;
var argc = isExpirationDateValid.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();
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.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;
}

/*************************************************************************\
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(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;
}

//  End -->
</script>Start Free Trial
[+][-]10.06.2004 at 11:46AM PDT, ID: 12240922

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.06.2004 at 11:52AM PDT, ID: 12240982

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.06.2004 at 11:57AM PDT, ID: 12241052

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.06.2004 at 12:04PM PDT, ID: 12241130

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.06.2004 at 12:51PM PDT, ID: 12241662

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.06.2004 at 12:53PM PDT, ID: 12241688

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.18.2004 at 11:35AM PDT, ID: 12340825

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.18.2004 at 12:03PM PDT, ID: 12341098

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]10.25.2004 at 02:33PM PDT, ID: 12405223

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.26.2004 at 01:11AM PDT, ID: 12408529

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Miscellaneous Web Development, E-Commerce
Tags: card, vaildator, credit, vercation
Sign Up Now!
Solution Provided By: Adesso21
Participating Experts: 1
Solution Grade: B
 
 
[+][-]10.26.2004 at 01:21PM PDT, ID: 12415246

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.27.2004 at 12:54PM PDT, ID: 12426386

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32