Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/06/2007, 21:13
monicoomar
 
Fecha de Ingreso: mayo-2007
Mensajes: 5
Antigüedad: 17 años, 9 meses
Puntos: 0
Validacion de formularios con

quisiera que alguien me ayude deseo validar un formulario la verdad se poco de lo que es Javascript tengo unos codigos de javascript pero no encuentro la manera de que me funcionen adentro de un archivo php para validar un formulario el codigo identifica cada caja de texto que esta vacia y da el mensaje pero ademas de eso si se encuentra como un numero dentro de la caja de texto "nombre" dice que esta incorrecto el dato y da el numero que se escribio pueden probarlo si queren para que vean a lo que me refiero solo guardenlo con extension html y les funcionara por si alguien lo necesita es muy util:

Código HTML:
<html>
<head>
</head>
<body bgcolor="#FFFFFF">
<center><span class="header">
<center>

<!--------------------------------------BEGIN REQUIRED----------------------------------------->
<!--BEGIN THE FORM-->
<table><tr><td>
<form name="main" method="get" action="">
<input type="text" width="30" name="name" style="border:1 solid #000000" size="20">
Nombre<br>
<input type="text" width="30" name="address" style="border:1 solid #000000" size="20">
Dirección<br>
<input type="text" width="30" name="age" style="border:1 solid #000000" size="20"> 
Edad<br>
<input type="text" width="30" name="zip" style="border:1 solid #000000" size="20"> 
C. Postal<br><br>
<center>
<input type="button" value="Enviar" onClick="javascript:validate();"> 
<input type="reset" value="Borrar"></center>
</form>
</td></tr></table>
<!--END THE FORM-->

<!--BEGIN FORM VALIDATION SCRIPT-->
<script language="JavaScript1.2">


var alphaChars="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
var numChars="0123456789";
var error;
var error_n;
var error_ad;
var error_a;
var error_z;
var errormsg;

//--------------------------Customise-------------------------------
var isNameReq=true; // True if Name field required else False
var isAddressReq=true; // True if Address field required else False
var isAgeReq=false; // True if Name Age required else False
var isZipReq=true; // True if Name Zip required else False
//------------------------------------------------------------------

function reset_error()
{
 error_n=false;
 error_ad=false;
 error_a=false;
 error_z=false;
 errormsg='Following Errors Occured ::\n_____________________________\n\n';
}

function validate_name()
{
 if(isNameReq)
 {
  if(document.main.name.value=="")
  {
   errormsg+='Por favor, entra tu nombre.\n';
   error_n=true;
   document.main.name.focus();
  }
 }
 for(var i=0; i<document.main.name.value.length; i++)
 {
  for(var j=0; j<alphaChars.length; j++)
  {
   if(alphaChars.charAt(j)==document.main.name.value.charAt(i))
   {
    break;
   }
   else
   {
    if(j==(alphaChars.length-1))
    {
     errormsg+='"' + document.main.name.value.charAt(i) + '"' + ' no es un carácter válido para el nombre.\n';
     error_n=true;
    }
   }
   if(error_n)
   {
    document.main.name.select();
   }
  }
 }
}

function validate_address()
{
 if(isAddressReq)
 {
  if(document.main.address.value=="")
  {
   errormsg+='Por favor, entra tu dirección.\n';
   error_ad=true;
   if(!error_n)
   {
    document.main.address.focus();
   }
  }
 }
}

function validate_age()
{
 if(isAgeReq)
 {
  if(document.main.age.value=="")
  {
   errormsg+='Por favor, entra tu edad.\n';
   error_a=true;
   if((!error_n)&&(!error_ad))
   {
    document.main.age.focus();
   }
  }
 }
 for(var i=0; i<document.main.age.value.length; i++)
 {
  for(var j=0; j<numChars.length; j++)
  {
   if(numChars.charAt(j)==document.main.age.value.charAt(i))
   {
    break;
   }
   else
   {
    if(j==(numChars.length-1))
    {
     errormsg+='"' + document.main.age.value.charAt(i) + '"' + ' es un carácter no válido para la edad.\n';
     error_a=true;
    }
   }
   if(error_a)
   {
    if((!error_n)&&(!error_ad))
    {
     document.main.age.select();
    }
   }
  }
 }
}

function validate_zip()
{
 if(isZipReq)
 {
  if(document.main.zip.value=="")
  {
   errormsg+='Por favor, entra el código postal.\n';
   error_z=true;
   if((!error_n)&&(!error_ad)&&(!error_a))
   {
    document.main.zip.focus();
   }
  }
 }
 for(var i=0; i<document.main.zip.value.length; i++)
 {
  for(var j=0; j<numChars.length; j++)
  {
   if(numChars.charAt(j)==document.main.zip.value.charAt(i))
   {
    break;
   }
   else
   {
    if(j==(numChars.length-1))
    {
     errormsg+='"' + document.main.zip.value.charAt(i) + '"' + ' no es un carácter válido para el código postal.\n';
     error_z=true;
    }
   }
   if(error_z)
   {
    if((!error_n)&&(!error_ad)&&(!error_a))
    {
     document.main.zip.select();
    }
   }
  }
 }
}

function validate()
{
 reset_error();
 validate_name();
 validate_address();
 validate_age();
 validate_zip();

 if(error_n||error_ad||error_a||error_z)
 {
  error=true;
 }
 else
 {
  error=false;
 }
 if(!error)
 {
  document.main.submit();
 }
 else
 {
  alert(errormsg);
 }
}

</script>
<!--END FORM VALIDATION SCRIPT-->
<!--------------------------------------END REQUIRED------------------------------------------->

</center><br>


</body>
</html> 
si alguien encuentra alguna manera de ligarlo con un archivo php sera bienvenida ña ayuda o si alguien tiene un codigo de validacion de formulario parecido tambien sera bienvenido solo necesito saber o los errores o como hacerlo con un ejemplo y sigo yo haciendole ayudenme porfavor me estancado en esa validacion porfavor ayudenme