codice:
function onlyNumeric(evt)
{
var theEvent = evt || window.event;
var theInput=theEvent.target;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode(key);
if(theInput.value.indexOf('.')==-1){// solo un punto è ammesso
var regex = /[0-9]|\./; //[0-9] or(|) punto (\.)
}else{
var regex = /[0-9]/;
}
if (!regex.test(key)) {
theEvent.returnValue = false;
if (theEvent.preventDefault) theEvent.preventDefault();
}
}
Forse bisognerebbe considerare anche l'eventualità di inserire numeri negativi