Cita:
function numOrlet(evt, valor) {
key = (evt.keyCode) ? evt.keyCode : evt.charCode;
if (key == 8) return true;
caracter = String.fromCharCode(key);
var pattner = /^(\d*)$/;
if(!pattner.test(caracter)) {
var pattner = /^([A-Za-z\s]*)$/;
if(pattner.test(caracter+valor)) { return true; } else { alert('no puedes insertar letras'); return false;}
} else {
var pattner = /^(\d*)$/;
if(pattner.test(caracter+valor)) { return true; } else { alert('no puedes insertar números'); return false;}
}
}
<input type="text" value="" onkeypress="return numOrlet(event, this.value)" />
key = (evt.keyCode) ? evt.keyCode : evt.charCode;
if (key == 8) return true;
caracter = String.fromCharCode(key);
var pattner = /^(\d*)$/;
if(!pattner.test(caracter)) {
var pattner = /^([A-Za-z\s]*)$/;
if(pattner.test(caracter+valor)) { return true; } else { alert('no puedes insertar letras'); return false;}
} else {
var pattner = /^(\d*)$/;
if(pattner.test(caracter+valor)) { return true; } else { alert('no puedes insertar números'); return false;}
}
}
<input type="text" value="" onkeypress="return numOrlet(event, this.value)" />