I want to be able to call cardcheck, and do all of the necissary checks to find if any fail, and therefore return false. What am I doing wrong??
function cardcheck(cardNumber, cardType){
var ccCheckRegExp = /[^\d ]/;
if(cardNumber.split(ccCheckRegExp)!=''){
alert('Incorrect Card Format');
return false;
} else if (cardNumber.length != 16){
alert('Incorrect Card Format');
return false;
} else {
switch(cardType)
{
case "switch":
if (modfunction(2) == false){
return false
}
break;
case "visa":
if (modfunction(5) == false){
return false;
}
break;
case "amex":
if (modfunction(0) == false){
return false;
}
break;
}
}
}
function modfunction(n) {
var i = n;
var isValid = false;
var numberProduct;
var numberProductDigitIndex;
var checkSumTotal = 0;
for (digitCounter = cardNumberLength - 1; digitCounter >= 0; digitCounter--){
checkSumTotal += parseInt (cardNumbersOnly.charAt(digitCounter));
digitCounter--;
numberProduct = String((cardNumbersOnly.charAt(digitCounter) * 2));
for (var productDigitCounter = 0; productDigitCounter < numberProduct.length; productDigitCounter++){
checkSumTotal +=
parseInt(numberProduct.charAt(productDigitCounter));
}
}
isValid = (checkSumTotal % 10 == i);
return isValid;
}
function cardcheck(cardNumber, cardType){
var ccCheckRegExp = /[^\d ]/;
if(cardNumber.split(ccCheckRegExp)!=''){
alert('Incorrect Card Format');
return false;
} else if (cardNumber.length != 16){
alert('Incorrect Card Format');
return false;
} else {
switch(cardType)
{
case "switch":
if (modfunction(2) == false){
return false
}
break;
case "visa":
if (modfunction(5) == false){
return false;
}
break;
case "amex":
if (modfunction(0) == false){
return false;
}
break;
}
}
}
function modfunction(n) {
var i = n;
var isValid = false;
var numberProduct;
var numberProductDigitIndex;
var checkSumTotal = 0;
for (digitCounter = cardNumberLength - 1; digitCounter >= 0; digitCounter--){
checkSumTotal += parseInt (cardNumbersOnly.charAt(digitCounter));
digitCounter--;
numberProduct = String((cardNumbersOnly.charAt(digitCounter) * 2));
for (var productDigitCounter = 0; productDigitCounter < numberProduct.length; productDigitCounter++){
checkSumTotal +=
parseInt(numberProduct.charAt(productDigitCounter));
}
}
isValid = (checkSumTotal % 10 == i);
return isValid;
}