So I have the line
var a = document.cardform.cardnumber.value.toString;
Then later:
else if (a.indexOf(' ')!=0 ||a.indexOf('+')!=0 || a.indexOf('-')!=0){
This checks that the user hasn't entered any unwanted +'s, -'s, or ' 's. The line seems to raise an error that looks like this:
Uncaught TypeError: undefined is not a function.
I'm confused as to what it's telling me. Is it saying undefined isn't a function, or that 'a' is an incompatible data type? How do I fix this problem?
String.prototype.toStringdoesn't have anindexOfproperty.toStringis a function, but in any case,valueis already a string.indexOfreturns -1. It will return 0 if that character is the first character in the string (assuming you actually calltoStringfirst).var a = document.cardForm.cardnumber.value.trim();