FUNCINES TEXTO JS - CONTAR VOCALES EN TEXTO

 <html>

<script>

 function vocales()

{

    var v_texto= document.getElementById("texto").value;

n=v_texto.length;  // total caracteres

    //alert (n);

var v_total=0;

for(i=0;i<n;i++)

{

   c=v_texto.charAt(i);

   c=c.toLowerCase();

   if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')

   {

     v_total++;

   }

}

//alert (v_total);

total.value=v_total;

}

</script>

  <body>

<form name="form1" method="post" action="">

<center>

<h1> funciones tipo TEXTO- TOTAL VOCALES</h1>

<h2>


nombre: 

<input type="text" name="texto" id="texto"> <p>

total vocales:

<input type="text" name="total" id="total"> <p>

<input type="button" onclick="vocales ()" name="r"

id="r" value="procesar"> <p>

</h2> 

</center>

</form>

  </body>

</html>

**************************************

Ejercicio Valida nombre:

Ingresar un nombre y validar que sea correcto, no lleve números ni caracteres especiales 


*************************************


<html>
<script>

 function VALIDA ()

{
  //  alert ("aqui");
    var v_texto= document.getElementById("texto").value;
n=v_texto.length;  // total caracteres
    
var sw=0;    // bandera
for(i=0;i<n;i++)
{
   c=v_texto.charAt(i);
   c=c.toLowerCase();
   if(c< 'a' || c >'z') 
   {
     sw=1;
   }
}

//alert (v_total);

if(sw==1)
{
   alert ("nombre incorrecto");
}
else
{
alert ("nombre ok"); 
}

}

</script>

  <body>

<form name="form1" method="post" action="">

<center>

<h1> funciones tipo TEXTO . VALIDA NOMBRE</h1>

<h2>



nombre: 

<input type="text" name="texto" id="texto"> <p>


<input type="button" onclick="VALIDA ()" name="r"

id="r" value="procesar"> <p>

</h2> 

</center>

</form>

  </body>

</html>

Comentarios

Entradas populares de este blog

ORDENAMIENTO DE VECTORES

EJERCICIO OPERACIONES EN PHP