[JavaScript] Validación campo input text (Solo debe aceptar números)

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();
  }
}
PandaGG
Lok'tar ogar

Dejar respuesta

Please enter your comment!
Please enter your name here

Sponsor

Últimos

Yabby Casino Customer Support: How Players Can Get Help with Account and Payment Questions

IntroductionIn the world of online gaming, customer support plays a crucial role, especially for beginners navigating platforms like Yabby Casino. Understanding how to access...

Casino en ligne retrait express : Guide complet pour les parieurs expérimentés

IntroductionLe monde des jeux d'argent en ligne a évolué de manière significative ces dernières années, et le concept de retrait express est devenu un...

Royal Panda Casino Review for Canadian Players

IntroductionRoyal Panda Casino has emerged as a popular online gaming destination for players in Canada. With its user-friendly interface and a wide variety of...

Exploring the Different Gaming Categories Available on Roobet

IntroductionRoobet is an online gaming platform that has gained popularity among players in Canada. It offers a variety of gaming categories that cater to...

Ausländisches Casino Bitcoin: Eine umfassende Analyse für erfahrene Spieler

EinführungIn der heutigen digitalen Welt hat sich das Glücksspiel erheblich verändert, insbesondere mit dem Aufkommen von Kryptowährungen wie Bitcoin. Ausländische Casinos, die Bitcoin als...