/* Javascript - Validar contenido de formularios */

 function val_texto(txt) /* Valida campos de texto evitando que haya código HTML */
 {
  menor=String.fromCharCode(60);
  mayor=String.fromCharCode(62);
  comilla=String.fromCharCode(39);
  comillas=String.fromCharCode(34);
  if (txt.value.indexOf(menor) != -1 || txt.value.indexOf(mayor) != -1 || txt.value.indexOf(comilla) != -1 || txt.value.indexOf(comillas) != -1) /* si el texto contiene <, >, ' ó " */
  {
   alert("This field cannot contain any of these characters: "+menor+" , "+mayor+" , "+comilla+" or "+comillas+" (simple or double quotes).");
   txt.value="";
   txt.focus();
  }
 }
 
 function val_mail(txt) /* Valida campos de texto evitando que haya código HTML y comprobando la validez como e-mail */
 {
  var filtro=/^[a-zA-Z](\.*\-*\w)*@(\-*\w\.*)*(\w{2,}\.)+(\w{2,})$/;
  if (txt.value.search(filtro) != 0)
  {
   alert("Please enter a valid e-mail address.");
   txt.value="";
   txt.focus();
  }
 }
  
 function val_contra(txt) /* Valida campos de texto evitando que haya código HTML, comprobando que la contraseña sea aceptable y que sea igual en los dos campos */
 {
  menor = String.fromCharCode(60);
  mayor = String.fromCharCode(62);
  comilla = String.fromCharCode(39);
  comillas = String.fromCharCode(34);
  if (txt.value.indexOf(menor) != -1 || txt.value.indexOf(mayor) != -1 || txt.value.indexOf(comilla) != -1 || txt.value.indexOf(comillas) != -1) /* si el texto contiene <, >, ' ó " */
  {
   alert("A password cannot contain any of these characters: "+menor+" , "+mayor+" , "+comilla+" or "+comillas+" (simple or double quotes).");
   document.getElementById("nreg_pwd").value="";
   document.getElementById("nreg_pwd2").value="";
   document.getElementById("nreg_pwd").focus();
  }
  if (txt.value.length < 6) // si la contraseña tiene menos de 6 caracteres
  {
   alert("A valid password must be at least 6 characters long.");
   document.getElementById("nreg_pwd").value="";
   document.getElementById("nreg_pwd2").value="";
   document.getElementById("nreg_pwd").focus();
  }
  if (document.getElementById("nreg_pwd2").value != "") // si el segundo campo de contraseña contiene algo
  {
   if (document.getElementById("nreg_pwd").value != document.getElementById("nreg_pwd2").value) // si los dos campos de contraseña no contienen lo mismo
   {
    alert("Both password fields must contain the same password");
    document.getElementById("nreg_pwd").value="";
    document.getElementById("nreg_pwd2").value="";
    document.getElementById("nreg_pwd").focus();
   }
  }
 }
 
 function val_numero(n) /* Valida campos numéricos evitando que haya caracteres no numéricos */
 {
  if (isNaN(n.value)) {
   alert("This field only admits numbers");
   n.value="";
  }
 }

/* Fin - Validar contenido de formularios */
