<input onkeypress="return checkInput(this)" >
function checkInput (elementRef) {
var keyCodeEntered = (event.which) ? event.which : (window.event.keyCode) ? window.event.keyCode : -1;
if ((keyCodeEntered >= 48) && (keyCodeEntered <= 57)) {
return true;
} else if (keyCodeEntered == 46) {
if ((elementRef.value) && (elementRef.value.indexOf('.') >= 0)) {
return false;
} else {
return true;
}
}
return false;
}