-1

Can anyone tell me what the two lines do here?

( charCode < 48 || charCode > 57))

I guess it means something like "or" or "do both"...

function numberCheck(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode > 31 && ( charCode < 48 || charCode > 57))
{
        document.getElementById("numonly").innerHTML = "Numbers Please!";

        return false;
}
else
{
        document.getElementById("numonly").innerHTML = "";
        return true;
}
}

So what your saying is that the code is looking for all characters except 48-57?

4

2 回答 2

5

Char codes 48 to 57 represent the number keys 0 - 9

|| means OR

therefore the expression will evaluate to true for any character that is not a number.

于 2013-10-24T17:59:20.700 回答
2

It is an "or". Seems like the code is looking for character that are NOT in the range of character code 48 through 57.

于 2013-10-24T17:57:43.680 回答