I am noticing something very strange when testing one of my functions that checks the validity of numbers, I first noticed it when testing the 'number.toString()[0]'. If I console logged (fLetter(019272)); the '0' is always showing '1'.
After checking online I couldn't find any issues associated with using the toString() method on numbers containing '0'.
function numberValidate(number) {
var numCheck = [0, 5, 7, 8, 9];
var fLetter = number.toString()[0];
if (number.match(/^\d{6}$/)) {
for (var i = 0; i < 5; i++) {
if (fLetter == numCheck[i]) {
return false;
} else {
return true;
}
}
}
}
I tried checking a few other test variables with and without applying the toString() method and got some results I couldn't understand. **Note - the toString() addition produced the same results (carried out in JSfiddle)
var numTest = 00000000;
var numTest1 = 20203020;
var numTest2 = 011000110100;
var numTest3 = 01928;
var numTest4 = 012345;
console.log(numTest); //Returned 0
console.log(numTest1); //Returned 20203020
console.log(numTest2); //Returned 1207996480
console.log(numTest3); //Returned 1928
console.log(numTest4); //Returned Returned 5349
Could any one shed any light on why I am getting these values returned? Thanks