Ver Mensaje Individual
  #15 (permalink)  
Antiguo 03/06/2010, 04:55
javier55
 
Fecha de Ingreso: septiembre-2003
Ubicación: Barcelona
Mensajes: 41
Antigüedad: 21 años, 6 meses
Puntos: 0
Respuesta: Validar formulario

A ver, no lo entiendo, si solo dejo el primer if, el de nombre y apellidos, funciona, si pongo algun if más ya no funciona, que estoy haciendo mal, ya que segun lo que comentáis y los ejemplos de diferentes webs, está bien, vas validando con if y si cumple todos muestra el ultimo alert ?? ,

Gracias anticipadas

Código Javascript:
Ver original
  1. function valida_envia(frm){
  2.      var nombre = frm.nombre ;
  3.      var apellido1 = frm.apellido1 ;
  4.      var apellido2 = frm.apellido2 ;
  5.      var ano = frm.ano;
  6.      var nif = frm.nif;
  7.      var direccion = frm.direccion;
  8.      var numero = frm.numero;
  9.      var cpostal = frm.cpostal;
  10.      var poblacion = frm.poblacion;
  11.      var email = frm.email;
  12.      var telefono = frm.telefono;
  13.      var password = frm.password;
  14.      var rpassword = frm.rpassword;
  15.      var number = nif.substr(0,nif.value.length-1);
  16.      var let = nif.substr(nif.value.length-1,1);
  17.      var number = number % 23;
  18.      var letra='TRWAGMYFPDXBNJZSQVHLCKET';
  19.      var letra=letra.substring(numero,numero+1);
  20.          
  21.           if ((nombre.value.length == 0 ) || (apellido1.value.length == 0 ) || (apellido2.value.lengthlength == 0 ) ) {
  22.                  alert("Tiene que escribir su nombre y dos apellidos");
  23.                  nombre.focus()
  24.                  return 0;
  25.           }
  26.           if ((ano <= 1910) || (ano >= 1992 ))  {
  27.                   alert("Eres muy mayor o muy joven para esto");
  28.                   ano.focus()
  29.                   return 0;
  30.          }
  31.          if (letra!=let) {
  32.                      alert('Dni erroneo');
  33.                      nif.focus()
  34.                      return 0;
  35.          }
  36.          if ((direccion.value.length == 0 ) || (numero.value.length == 0 ) ) {
  37.                       alert("Por favor rellene dirección y numero");
  38.                      direccion.focus()
  39.                      return 0;
  40.          }
  41.          if (cpostal.value.length < 5 )  {
  42.                       alert("El c.Postal debe de ser de 5 dígitos");
  43.                       cpostal.focus()
  44.                       return 0;
  45.           }
  46.           if (poblacion.value.length == 0 ) {
  47.                       alert("Debes de rellenar el campo población");
  48.                       poblacion.focus()
  49.                       return 0;
  50.           }
  51.           if (/^w+([.-]?w+)*@w+([.-]?w+)*(.w{2,3})+$/.test(email)) {
  52.                      alert("Debes de rellenar bien el campo Email");
  53.                      email.focus()
  54.                      return 0;
  55.           }
  56.           if (telefono.value.length < 9 )  {
  57.                      alert("Introduce un teléfono correcto(9 dígitos)");
  58.                      telefono.focus()
  59.                      return 0;
  60.            }
  61.            if (password.value.length < 4 )  {
  62.                      alert("la contraseña debe de ser entre 4 y 8 caracteres");
  63.                      password.focus()
  64.                      return 0;
  65.            }
  66.            if (rpassword != password) {
  67.                     alert("Las contraseñas no coinciden, revíselo");
  68.                     rpassword.focus()
  69.                     return 0;
  70.            }
  71. alert("Muchas gracias por enviar el formulario");
  72.          
  73. }