Hola, lo que estás buscando debe ser algo así:
Código HTML:
Ver original
// Una vez cargado el documento..
window.onload = function()
{
// El siguiente código se ejecuta cuando se hace submit del formulario
document.getElementById('formulario').onsubmit = function(e)
{
var input = document.getElementById('numerico').value
// Si en el input se escribió algo y fueron caracteres no numéricos, se muestra una alerta y se cancela el submit
if( input !== '' && ! ( /^[0-9]+$/.test(input) ) )
{
e.preventDefault()
alert('El campo debe ser nulo o numérico')
return false
}
}
}
</script>
<form id="formulario" action="script.html">
<input type="text" id="numerico" />
<input type="submit" />
</form>
</body>
</html>