Ver Mensaje Individual
  #2 (permalink)  
Antiguo 25/06/2012, 19:52
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 16 años, 10 meses
Puntos: 1567
Respuesta: campo de texto con solo letras y numeros

Esto ya ha sido respondido muchas veces en el foro, para la próxima te recomiendo hagas un búsqueda más refinada
Código HTML:
Ver original
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml">
  4. <title>titulo</title>
  5. <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  6. <script type="text/javascript">
  7. function validar(idcampo, mensaje) {
  8. var cadena = document.getElementById(idcampo).value;
  9. var exp_reg  = /^[a-z\d\u00C0-\u00ff]+$/i; // expresión regular para letras(máy o minus), acentuadas o no, y números
  10. var verifica = exp_reg.test(cadena);
  11. if (verifica == true){
  12. //alert('ok');
  13. document.getElementById(mensaje).innerHTML = "Correcto";
  14. }else {
  15. //alert('error');
  16. document.getElementById(mensaje).innerHTML = "Incorrecto";
  17. return false;
  18. }
  19. }
  20. </head>
  21. <form action="#">
  22. <div>
  23. <label for="nombre">Nombre</label>
  24. <input type="text" onkeyup="validar(this.id,'mensaje_nombre');" id="nombre" />
  25. <span id="mensaje_nombre"><!-- aqui el mensaje a medida que se introducen caracteres --></span>
  26. </div>
  27. </form>
  28. </body>
  29. </html>
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.

Última edición por emprear; 25/06/2012 a las 20:00