Ver Mensaje Individual
  #5 (permalink)  
Antiguo 25/07/2016, 14:57
alvaro_trewhela
Invitado
 
Mensajes: n/a
Puntos:
Respuesta: Como validar email 2 veces en formulario

prueba con esto:

Código HTML:
Ver original
  1.     <head>
  2.    
  3.     <script type="text/javascript">
  4.    
  5.     window.onload = function() {
  6.     var mail = document.getElementById("mail2");
  7.         mail.onpaste = function(e){
  8.         e.preventDefault();
  9.         alert('no paste plx!!');
  10.         };
  11.     };
  12.    
  13.     function validarMail(id) {
  14.     var patron = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  15.         if (patron.test(document.getElementById(id).value)){
  16.         return true;
  17.         }
  18.     return false;
  19.     }
  20.    
  21.     function valida(id1, id2){
  22.     var mail1 = document.getElementById(id1);
  23.     var mail2 = document.getElementById(id2);
  24.         if(validarMail(id1) && validarMail(id2) && mail1.value == mail2.value){
  25.         return true;
  26.         }
  27.     return false;
  28.     }
  29.    
  30.     </script>
  31.    
  32.    
  33.     </head>
  34.     <body>
  35.    
  36.         <form method="post" action="" onsubmit="if(!valida('mail1', 'mail2')){ alert('error mails!!'); return false; }">
  37.         <input type="text" value="" name="mail1" id="mail1" /><br/>
  38.         <input type="text" value="" name="mail2" id="mail2" /><br/>
  39.         <input type="submit" value="go!">
  40.         </form>
  41.        
  42.         <br/>
  43.         <?php
  44.        
  45.         echo $_POST["mail1"] ." - ".$_POST["mail2"];
  46.        
  47.         ?>
  48.     </body>
  49. </html>

Última edición por alvaro_trewhela; 25/07/2016 a las 15:08