No permitir ingresar ciertos caracteres en un input


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function validarn(e) { // 1
  2. tecla = (document.all) ? e.keyCode : e.which; // 2
  3. if (tecla==8) return true; // 3
  4. if (tecla==9) return true; // 3
  5. if (tecla==11) return true; // 3
  6. patron = /[A-Za-zñÑ'áéíóúÁÉÍÓÚàèìòùÀÈÌÒÙâêîôûÂÊÎÔÛÑñäëïöüÄËÏÖÜ\s\t]/; // 4
  7.  
  8. te = String.fromCharCode(tecla); // 5
  9. return patron.test(te); // 6
  10. }
  11.  
  12.  
  13.  
  14. <input type="text" class="inputText" name="nombre" onkeypress="return validarn(event)" />

URL: http://www.telefonica.net/web2/blas-mar/validarformu.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.