Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/03/2013, 05:55
carolina3
 
Fecha de Ingreso: agosto-2011
Ubicación: barcelona
Mensajes: 237
Antigüedad: 12 años, 9 meses
Puntos: 1
validar campos de email

hola muy buenas tengo un script para validar los campos de mi formulario y el de email no me lo valida aun poniendo un email correcto no entiendo ya he provado dos maneras diferentes y nada de nada este seria el código del script y el form

Código Javascript:
Ver original
  1. <script type="text/javascript">
  2. function validarForm3() {
  3.     valor0 = document.getElementById("nombre_user").value;
  4.     valor1 = document.getElementById("email_user").value;
  5.     valor2 = document.getElementById("telefono").value;
  6.  if(valor0 == null || valor0.length == 0 || /^\s+$/.test(valor0) ) {//valor del nombre
  7.      alert('[ERROR] El campo debe tener un valor de...');
  8.   return false;
  9.  
  10.     }
  11. else if( !(/^\d{9}$/.test(valor2)) ) {//valor del telefono
  12.     alert('[ERROR] El campo debe tener un valor numerico');
  13.   return false;
  14. }
  15.      
  16.    
  17. else if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3,4})+$/.test(valor1)){//valor del email
  18.    alert("La dirección de email " + valor + " es correcta.");
  19.   } else {
  20.    alert("La dirección de email es incorrecta.");
  21.  
  22.   return false;
  23. }
  24.  
  25.  
  26.   return true;
  27. }
  28. </script>


y este el formulario:

Código HTML:
Ver original
  1. <form action="final_compra.php" method="post" name="form3" id="form3" onsubmit="return validarForm3();">
  2.        <table align="center">
  3.          <tr valign="baseline">
  4.            <td nowrap="nowrap" align="right">Email_user:</td>
  5.            <td><input name="email_user" type="text" id="email_user" value="" size="32" /></td>
  6.          </tr>
  7.          <tr valign="baseline">
  8.            <td nowrap="nowrap" align="right">Nombre_user:</td>
  9.            <td><input name="nombre_user" type="text" id="nombre_user" value="" size="32" /></td>
  10.          </tr>
  11.          <tr valign="baseline">
  12.            <td nowrap="nowrap" align="right">Apellido_user:</td>
  13.            <td><input name="telefono" type="text" id="telefono" value="" size="32" /></td>
  14.  
  15.          </tr> <tr>
  16.         <td>&nbsp;</td>
  17.         <td><input type="submit" name="button2" id="button2" value="Enviar" /></td>
  18.       </tr>
  19.     </table></form>

gracias