Ver Mensaje Individual
  #4 (permalink)  
Antiguo 14/02/2013, 13:53
Avatar de emprear
emprear
Colaborador
 
Fecha de Ingreso: junio-2007
Ubicación: me mudé
Mensajes: 8.388
Antigüedad: 17 años, 8 meses
Puntos: 1567
Respuesta: ¿Cómo agrego una validación de e-mail en una función JavaScript?

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. //<![CDATA[
  8. /* script */
  9. function validar(){
  10.    
  11. var emailReg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
  12. var email_ingresado = document.getElementById('email').value;
  13. if(!emailReg.test(email_ingresado)) {
  14. alert('email no válido');
  15. return false;
  16. }
  17. }
  18. //]]>
  19. </head>
  20. <form action="x.html" method="post" onsubmit="return validar();">
  21. <input type="text" id="email" name="email" />
  22. <input type="submit" value="enviar" />
  23. </form>
  24. </body>
  25. </html>
Para la próxima hacé una búqueda más intensiva en FDW, hay numerosas respuestas a eso

SAludos
__________________
La voz de las antenas va, sustituyendo a Dios.
Cuando finalice la mutación, nueva edad media habrá
S.R.