martes, 4 de marzo de 2025

Uso de las funciones de texto para la validación de strings

La siguiente página demostrará la verificación de un texto y una serie de números eliminando caracteres especiales o desubicados en cada uno.

Código:

<html>
<head>
<title>
Eliminación Caracteres
</title>
</head>
<body bgcolor=lightgreen>
<form name="form1" method="post" action="">
<center><b><h1>PÁGINA - ELIMINACIÓN CARACTERES ESPECIALES</h1></b>
Ingrese País:
<input type="text" name="pais" id="pais"><p>
Resultado:
<input type="text" name="resultado" id="resultado"><p>
Cédula:
<input type="text" name="cedula" id="cedula"><p>
Resultado:
<input type="text" name="Resultado" id="Resultado"><p>
<input type="button" value="Procesar" Onclick="Procesar()">
</center>
</form>
</body>
<script>
function Procesar()
{
var v_texto = document.getElementById("pais").value;
var v_num = document.getElementById("cedula").value;
var n = v_texto.length;
var m = v_num.length;
res = "";
resd = "";
for(i=0;i<n;i++)
{
c=v_texto.charAt(i);
if(c>="A"&&c<="Z")
{
res = res+c;
}
if(c>="a"&&c<="z")
{
res = res+c;
}
if(c==" ")
{
break;
}
}
for(j=0;j<m;j++)
{
d=v_num.charAt(j);
if(d>="0"&&d<="9")
{
resd = resd + d;
}
}
resultado.value=res;
Resultado.value=resd;
}
</script>
</html>

Funcionalidad de la Página:



No hay comentarios:

Publicar un comentario