HTML:
<form name="miformulario"> <td align=right>Cod.Postal:</td><td align=left><input type="text" name="codigo" id="idcodigo" maxlength="5"></td> </form>
JavaScript:
window.addEventListener("load", function() { miformulario.codigo.addEventListener("keypress", soloNumeros, false); }); //Solo permite introducir numeros. function soloNumeros(e){ var key = window.event ? e.which : e.keyCode; if (key < 48 || key > 57) { e.preventDefault(); } }