I got my hands on this JavaScript code which enables to validate a textbox to accept a numeric keypress on the keyboard.
function Numeric(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode > 31 && ( charCode < 48 || charCode > 57))
{
document.getElementById("span").innerHTML = "Numbers Please!";
alert("numbers only pls");
return false;
}
else
{
document.getElementById("span").innerHTML = "";
return true;
}
}
HTML Number:<input type="text" id="num" name="num" onkeypress="return Numeric(event)" /><span id="span"></span><br />
This works well, but I have two questions:
(1). Can I get a clear explanation on what goes on in this part of the code?
function Numeric(evt)
{
var charCode = (evt.which) ? evt.which : event.keyCode;
if (charCode > 31 && ( charCode < 48 || charCode > 57))
(2). Will this code be effective on all kinds of keyboards?