M
Marshall Dudley
I have some javascript code which was supplied by a credit card
processing company to check their card numbers for validity and to check
the cvv. It fails on a cvv of 000, which is valid, and complains that
the cvv was left out, when it was not.
Here is the code:
/*This function checks if a field is empty.*/
function emptyField(textObj) {
if (textObj.length == 0) return true;
for (var i=0; i<textObj.length; ++i) {
var ch = textObj.charAt(i);
if (ch != ' ' && ch != '\t') return false;
}
return true;
}
if (emptyField(document.CC.x_Card_Code.value)) {
alert("Error: Your credit card security code is
required. Please correct this error and try again.");
document.CC.x_Card_Code.focus();
return false;
}
I don't know javascript very well, but don't see why it says that it is
blank with the number of 000 entered, when I walk through the code, I
get that emptyField should return a false. Can anyone tell me what
needs changing to make it work, or why it thinks the length is 0, when
it is 3, or thinks a zero is the same as a null or tab?
Thanks,
Marshall
processing company to check their card numbers for validity and to check
the cvv. It fails on a cvv of 000, which is valid, and complains that
the cvv was left out, when it was not.
Here is the code:
/*This function checks if a field is empty.*/
function emptyField(textObj) {
if (textObj.length == 0) return true;
for (var i=0; i<textObj.length; ++i) {
var ch = textObj.charAt(i);
if (ch != ' ' && ch != '\t') return false;
}
return true;
}
if (emptyField(document.CC.x_Card_Code.value)) {
alert("Error: Your credit card security code is
required. Please correct this error and try again.");
document.CC.x_Card_Code.focus();
return false;
}
I don't know javascript very well, but don't see why it says that it is
blank with the number of 000 entered, when I walk through the code, I
get that emptyField should return a false. Can anyone tell me what
needs changing to make it work, or why it thinks the length is 0, when
it is 3, or thinks a zero is the same as a null or tab?
Thanks,
Marshall