FunctionedOut
June 5th, 2004, 12:27 AM
Hello All
I have written this function which is supposed to:
return true if a string consists of a sequence of six digits otherwise it returns false.
My problem is when I put 1234c5 to test the function (or any other string which contains a alphabetical character), it returns true and not false, which it should be returning..
function check(aString)
{
if (aString.length !=6)
{
return false
};
for (var i=0; i<6; i++)
{
if (!isNumeric(aString.charAt(i)))
{
return false
}
else
{
return true
}
};
}
Can anyone help me deduce where I am going wrong with this. I know I can place the last return statement outside the for loop but I really would like to know why this code is not working as it should. It's driving me crazy. :mad: Any suggestions?
Thank you.
I have written this function which is supposed to:
return true if a string consists of a sequence of six digits otherwise it returns false.
My problem is when I put 1234c5 to test the function (or any other string which contains a alphabetical character), it returns true and not false, which it should be returning..
function check(aString)
{
if (aString.length !=6)
{
return false
};
for (var i=0; i<6; i++)
{
if (!isNumeric(aString.charAt(i)))
{
return false
}
else
{
return true
}
};
}
Can anyone help me deduce where I am going wrong with this. I know I can place the last return statement outside the for loop but I really would like to know why this code is not working as it should. It's driving me crazy. :mad: Any suggestions?
Thank you.