Validación de Correo
El siguiente Codigo nos muestra la validacion del correo electronico en Funcion A Html y JavaScript <html> | |
<head>
| |
| <title>Validar correo</title> | |
| <script type="text/javascript"> | |
| function validarcorreo(){ | |
| var i; var correo; | |
| correo=document.form.correo.value; | |
| var c=0; | |
| var p=0; | |
| var s=""; | |
| s=correo.length; | |
| for (i=1;i<=s;i++) | |
| { | |
| if(correo.substring(i-1,i)=="@") | |
| { | |
| c++; | |
| } | |
| if(c==1) | |
| { | |
| if(correo.substring(i-1,i)==".") | |
| { | |
| p++; | |
| } | |
| } | |
| } | |
| if(c==1 && p==2 || p==1) | |
| { | |
| alert("Correo valido =)!!"); | |
| }else{ | |
| alert("CORREO NO VALIDO!!"); | |
| document.form.correo.value=""; | |
| } | |
| } | |
| </script> | |
| </head> | |
| <body bgcolor="F6F3D3"> | |
| <div align="center"> | |
| <h3>INGRESE EL CORREO</H3> | |
| <form name="form"> | |
| <input type="text" name="correo" onchange="validarcorreo()" size="60"/><br><br> | |
| <input type="submit" value="VER" > | |
| </form> | |
| </div> | |
| </body> | |
| </html> |
Validación de Fecha
| El siguiente Ejemplo nos muestra la validación de la fecha teniendo su propio formato utilizando funciones <html> | |
| <head> | |
| <title>Validacion de fecha</title> | |
| <script type="text/javascript"> | |
| function validarfecha(a){ | |
| if(a.length!=10) | |
| { | |
| alert("Fecha invalida");return; | |
| } | |
| if((a.substring(2,3)!="/") || (a.substring(5,6)!="/")) | |
| { | |
| alert("Fecha invalida");return; | |
| } | |
| if (a.substring(0,2)>31) | |
| { | |
| alert("Fecha invalida");return; | |
| } | |
| if (a.substring(3,5)>12) | |
| { | |
| alert("Fecha invalida");return; | |
| } | |
| if (a.substring(6,10)!=2012) | |
| { | |
| alert("Fecha invalida");return; | |
| } | |
| alert("Fecha valida"); | |
| } | |
| </script> | |
| </head> | |
| <body bgcolor="F6F3D3"> | |
| <form name="form"> | |
| <input type="text" name="fecha" onchange="validarfecha(this.value)" /> | |
| <input type="button" name="validar" value="Validar"> | |
| </form> | |
| </body> | |
| </html> |
Validacion Numero de Telefono
La Siguiente Funcion NosMuestra La Validacion del Numero de Telefono Teniendo como Parametros los Digitos Correspondientes
| |
| <head> | |
| <title>Validacion de numero de telefono</title> | |
| <script type="text/javascript"> | |
| function esnumero(parametro){ | |
| var d; | |
| var c | |
| d=parametro.length | |
| for(i=0; i<d; i++) | |
| { | |
| c=parametro.substring(i,i+1); | |
| if((c!="-") && (c!="0") && (c!="1") && (c!="2") && (c!="3") && (c!="4") && (c!="5") && (c!="6") && (c!="7") && (c!="8") && (c!="9")) | |
| return false; | |
| } | |
| return true; | |
| } | |
| function validarnumero(){ | |
| var b=document.getElementById("telefono").value; | |
| if(b.length!=11) | |
| { | |
| alert("Telefono invalido");return; | |
| } | |
| if((b.substring(3,4)!="-") || (b.substring(7,8)!="-")) | |
| { | |
| alert("telefono invalido");return; | |
| } | |
| if(esnumero(b)==false) | |
| { | |
| alert("Ingrese numeros por favor");return; | |
| } | |
| alert ("Telefono valido") | |
| } | |
| </script> | |
| </head> | |
| <body bgcolor="F6F3D3"> | |
| <form name="prueba"> | |
| <input type="text" name="telefono" id="telefono"onChange="validarnumero()" /> | |
| <input type="button" name="validar" value="Validar"> | |
| </form> | |
| </body> | |
| </html> |
Muestra El Mayor Y El Segundo Mayor
| La siguiente Funcion Que Veremos Es La De Mostrar El Mayor Y Segundo Mayor Dentro De Una Funcion. <html> | |
| <head> | |
| <title>Generar y sacar el mayor y el segundo mayor</title> | |
| </head> | |
| <body bgcolor="F6F3D3" onload="generar()"> | |
| <form id="practica" name="practica"> | |
| <center><h2>Calcular el mayor y el segundo mayor</h2></center> | |
| <center> | |
| <div id="divuno"></div> | |
| <input type="submit" id="enviar" name="enviar" onclick="calcular()" value="Calcular"> | |
| </center> | |
| </form> | |
| </body> | |
| </html> | |
| <script type="text/javascript"> | |
| function generar() | |
| { | |
| var strcadena=""; | |
| for(i=0; i<10 ;i++) | |
| { | |
| strcadena=strcadena+"<input type='text' name='valor"+i+"' id='valor"+i+"'value=0><br><br>"; | |
| } | |
| document.getElementById("divuno").innerHTML=strcadena; | |
| } | |
| function calcular() | |
| { | |
| var mayor=0; | |
| var mayordos=0; | |
| for(i=0; i<10; i++) | |
| { | |
| if(parseInt(document.forms["practica"]["valor"+i].value) > parseInt(mayor)) | |
| mayor= parseInt(document.forms["practica"]["valor"+i].value); | |
| if((document.forms["practica"]["valor"+i].value) > parseInt(mayordos) && (document.forms["practica"]["valor"+i].value) < parseInt(mayor)) | |
| mayordos= parseInt(document.forms["practica"]["valor"+i].value); | |
| } | |
| alert("El mayor es "+mayor); | |
| alert("El segundo mayor es "+mayordos); | |
| } | |
| </script> |
Validacion de Ruc
El siguiente Codigo Hace La validacion De Si Una Persona Es Natural O Juridica En Donde Hace El Llamado A Una Función Para Su Respectivo Proceso
<html><head>
<title>Validacion de RUC</title>
</head><body bgcolor="F6F3D3"><center>
<h1>Validación de Ruc para personas Naturales</h1>
<script type="text/javascript">
function validarruc()
{
var acumulado=0;
var instancia;
var ruc=document.getElementById("ruc").value;
for(i=0 ;i<ruc.length; i++)
{
z=ruc.substring(i,i+1);
if((z!="0") && (z!="1") && (z!="2") && (z!="3") && (z!="4") && (z!="5") && (z!="6") && (z!="7") && (z!="8") && (z!="9"))
{
alert("Ruc Invalido");return;
}
}
if(ruc.length!=13)
{
alert("Ruc Invalido");return;
}
if((ruc.substring(0,2)>22) || (ruc.substring(0,2)<1))
{
alert("Ruc Invalido");return;
}
if(ruc.substring(2,3)>=6)
{
alert("Ruc Invalido");return;
}
for(i=1; i<=9; i++)
{
if (i%2!=0)
{
instancia=ruc.substring(i-1,i)*2;
if(instancia>9) instancia-=9;
}
else instancia=ruc.substring(i-1,i);
acumulado+=parseInt(instancia);
}
while (acumulado>0)
acumulado-=10;
if(ruc.substring(9,10)!=(acumulado*-1))
{
alert("Ruc Invalido");return;
}
if((ruc.substring(10,13)!=001) && (ruc.substring(10,13)!=002) && (ruc.substring(10,13)!=003) && (ruc.substring(10,13)!=004) && (ruc.substring(10,13)!=005) && (ruc.substring(10,13)!=006) && (ruc.substring(10,13)!=007) && (ruc.substring(10,13)!=008) && (ruc.substring(10,13)!=009))
{
alert("Ruc Invalido");return;
}
alert("Ruc Valido");
}
</script>
</center>
<form name="form">
<center>
<h2>Formato</h2>
<br><br>
<input type="text" name="ruc" id="ruc">
<input type="button" id="enviar" onclick="validarruc()" value="Validar"><br><br><br>
</form>
</body></html>
Suma De Numeros En varias Cajas De Textos
El Codigo que se muestra nos enseña como validar y sumar números en varias cajas de texto con sus respectivas funciones.
<html>
<head>
<body onload="cargar()">
<form>
<input type='submit' name='enviar1' value='Enviar' OnClick='prueba()'>
<div id='contenedor1'>
</form>
</body>
</head>
</html>
<script type='text/javascript'>
function cargar()
{
var strhtml="";
for (i=1;i<=10;i++)
{
strhtml=strhtml+"<input type='text' id='valor0"+i+"'><br>";
}
document.getElementById('contenedor1').innerHTML=strhtml;
}
function prueba()
{
var suma=0;
for (i=1;i<=10;i++)
{
suma+= parseInt(document.getElementById("valor0"+i).value);
}
alert (suma);
}
</script>
<html>
<head>
<body onload="cargar()">
<form>
<input type='submit' name='enviar1' value='Enviar' OnClick='prueba()'>
<div id='contenedor1'>
</form>
</body>
</head>
</html>
<script type='text/javascript'>
function cargar()
{
var strhtml="";
for (i=1;i<=10;i++)
{
strhtml=strhtml+"<input type='text' id='valor0"+i+"'><br>";
}
document.getElementById('contenedor1').innerHTML=strhtml;
}
function prueba()
{
var suma=0;
for (i=1;i<=10;i++)
{
suma+= parseInt(document.getElementById("valor0"+i).value);
}
alert (suma);
}
</script>
Validacion de Multiplos De 5
<head>
<title></title>
</head>
<body>
<form name="form">
Valor<input type="text" name="valor" id="valor">
<input type="submit" name="enviar" id="enviar" value="Enviar" OnClick="prueba()">
</script>
</form>
</body>
</html>
<script type="text/javascript">
function prueba()
{
z=0;
x=document.getElementById("valor").value;
z=x%5
if(z==0)
{
alert("Si es multiplo de 5");
}
else{
alert("error");
}
}
</script>
<title></title>
</head>
<body>
<form name="form">
Valor<input type="text" name="valor" id="valor">
<input type="submit" name="enviar" id="enviar" value="Enviar" OnClick="prueba()">
</script>
</form>
</body>
</html>
<script type="text/javascript">
function prueba()
{
z=0;
x=document.getElementById("valor").value;
z=x%5
if(z==0)
{
alert("Si es multiplo de 5");
}
else{
alert("error");
}
}
</script>
Suma De Dos Valores
<html>
<head>
<body>
<form>
VALOR 1 <input type='text' id='valor1' name='valor1'>
VALOR 2 <input type='text' id='valor2' name='valor2'>
<input type='submit' name='enviar1' value='Enviar' OnClick='prueba()'>
<div id='contenerdor1'>
</div>
</form>
</body>
</head>
</html>
<script type='text/javascript'>
function cargar()
{
var strhtml="";
for (i=1;i<=10;i++)
{
srthtml=strhtml+"<input type= 'text' id='valor0'"+i+"'><br>";
}
document.getElementById('contenedor1').innerHTML=strhtml;
}
function prueba()
{
var z;
var x=document.getElementById('valor1').value;
var y=document.getElementById('valor2').value;
z=parseInt(x)+parseInt(y);
alert(z);
}
</script>
<head>
<body>
<form>
VALOR 1 <input type='text' id='valor1' name='valor1'>
VALOR 2 <input type='text' id='valor2' name='valor2'>
<input type='submit' name='enviar1' value='Enviar' OnClick='prueba()'>
<div id='contenerdor1'>
</div>
</form>
</body>
</head>
</html>
<script type='text/javascript'>
function cargar()
{
var strhtml="";
for (i=1;i<=10;i++)
{
srthtml=strhtml+"<input type= 'text' id='valor0'"+i+"'><br>";
}
document.getElementById('contenedor1').innerHTML=strhtml;
}
function prueba()
{
var z;
var x=document.getElementById('valor1').value;
var y=document.getElementById('valor2').value;
z=parseInt(x)+parseInt(y);
alert(z);
}
</script>
Validacion De Numeros Binarios
<html>
<head>
<b>Clase25-09-2012</b>
</head>
<body>
<form>
<input type="text" name="nota1" onChange = "validar(this.value)" >
<input type ="button" value="Validar" onClick="resultado()" >
</form>
</body>
<script type="text/javascript">
function validar(x){
a=0
y= x.length
for(i=0; i<y; i++){
z= x.substring(i,i+1);
if((z=="0") || (z=="1" ) ){
a=a+1
}
}
if (a == y){
alert("si es binario")}
else{
alert("No es binario")
}
}
</script>
</html>
<head>
<b>Clase25-09-2012</b>
</head>
<body>
<form>
<input type="text" name="nota1" onChange = "validar(this.value)" >
<input type ="button" value="Validar" onClick="resultado()" >
</form>
</body>
<script type="text/javascript">
function validar(x){
a=0
y= x.length
for(i=0; i<y; i++){
z= x.substring(i,i+1);
if((z=="0") || (z=="1" ) ){
a=a+1
}
}
if (a == y){
alert("si es binario")}
else{
alert("No es binario")
}
}
</script>
</html>
Caja De Texto Que Solo Permite El Ingreso De Numeros
<html>
<head>
<script type="text/javascript">
function validacion(f) {
if (isNaN(f.campo_a_validar.value)) {
alert("Error:\nEste campo debe tener sólo números.");
f.campo_a_validar.focus();
return (false);
}
}
</script>
</head>
<body>
<form method="post" action="" onsubmit="return validacion(this)">
Escriba el numero: <input type="text" name="campo_a_validar" value=""><br>
</form>
</body>
</html>
<head>
<script type="text/javascript">
function validacion(f) {
if (isNaN(f.campo_a_validar.value)) {
alert("Error:\nEste campo debe tener sólo números.");
f.campo_a_validar.focus();
return (false);
}
}
</script>
</head>
<body>
<form method="post" action="" onsubmit="return validacion(this)">
Escriba el numero: <input type="text" name="campo_a_validar" value=""><br>
</form>
</body>
</html>
Muestra El texto Almacenado En La Caja De Texto
<html>
<head>
</head>
<body>
NOMBRE: <input type= "text" onchange= "holamundo()" id="idex">
<script type="text/javascript">
function holamundo()
{
alert (document.getElementById ("idex").value);
}
</script>
</body>
</html>
<head>
</head>
<body>
NOMBRE: <input type= "text" onchange= "holamundo()" id="idex">
<script type="text/javascript">
function holamundo()
{
alert (document.getElementById ("idex").value);
}
</script>
</body>
</html>
Cuestionario Utilizando Checkbox Y Select Option
El siguiente codigo esta escrito en Html y a su vez utilizando controles
<html>
<head>
</head>
<form>
<body>
¿Que lenguaje de programacion conoce? <br>
<input type= "checkbox" name= "escoje" value="1">C#<br>
<input type= "checkbox" name= "escoje" value="2">JAVA<br>
<input type= "checkbox" name= "escoje" value="3">Phyton<br>
<input type= "checkbox" name= "escoje" value="4">Visual Basic<br>
<br>
¿Cuantos Lenguajes de bases de datos conoce? <br>
<input type= "checkbox" name= "leng" value="1">SQL<br>
<input type= "checkbox" name= "leng" value="2">POSGREL<br>
<input type= "checkbox" name= "leng" value="3">FREEBSD<br>
<input type= "checkbox" name= "leng" value="4">ORACLE<br>
<br>
<br>
¿Que sistema operativo utiliza? <br>
<select name="tipo" size="1">
<option value="1"> Windows 7
<option value="2"> Windows 8
<option value="3"> Centos
<option value="4"> Ubuntu
</select>
<br>
<br>
¿Que tipo de servidor es mejor? <br>
<select name="servidor" size="1">
<option value="1"> Windows Server
<option value="2"> Fedora
<option value="3"> Centos
<option value="4"> Rhat
</select>
</body>
</form>
</html>
<html>
<head>
</head>
<form>
<body>
¿Que lenguaje de programacion conoce? <br>
<input type= "checkbox" name= "escoje" value="1">C#<br>
<input type= "checkbox" name= "escoje" value="2">JAVA<br>
<input type= "checkbox" name= "escoje" value="3">Phyton<br>
<input type= "checkbox" name= "escoje" value="4">Visual Basic<br>
<br>
¿Cuantos Lenguajes de bases de datos conoce? <br>
<input type= "checkbox" name= "leng" value="1">SQL<br>
<input type= "checkbox" name= "leng" value="2">POSGREL<br>
<input type= "checkbox" name= "leng" value="3">FREEBSD<br>
<input type= "checkbox" name= "leng" value="4">ORACLE<br>
<br>
<br>
¿Que sistema operativo utiliza? <br>
<select name="tipo" size="1">
<option value="1"> Windows 7
<option value="2"> Windows 8
<option value="3"> Centos
<option value="4"> Ubuntu
</select>
<br>
<br>
¿Que tipo de servidor es mejor? <br>
<select name="servidor" size="1">
<option value="1"> Windows Server
<option value="2"> Fedora
<option value="3"> Centos
<option value="4"> Rhat
</select>
</body>
</form>
</html>
Generacion Automatica De Una Frase Cualquiera
El siguiente codigo nos muestra la utilizacion de JavaScript donde muestra solo un Mensaje
<html>
<head>
</head>
<body>
NOMBRE: <input type="text" onkeypress ="holamundo()" id ="idex">
<script type= "text/javascript">
function holamundo()
{
alert ("hola mundo");
}
</script>
</body>
</html>
<html>
<head>
</head>
<body>
NOMBRE: <input type="text" onkeypress ="holamundo()" id ="idex">
<script type= "text/javascript">
function holamundo()
{
alert ("hola mundo");
}
</script>
</body>
</html>
Genera el Numero Mayor De Una Caja De Texto
El siguiente codigo nos muestra el mayor de los numeros que estan ingresados en una caja de texto teniendo como base Html Y Javascript
<html>
<head>
<title>funcion generar y mostrar el mayor</title>
</head>
<body bgcolor="CCFFFF" onload="generar()">
<form id="form1"name="form1">
<div id="divuno">
</form>
</body>
<script type="text/javascript">
function generar()
{
var strcadena="";
for(i=0;i<10;i++)
{
strcadena+="<input type ='text' id='texto"+i+"' name='texto"+i+"'onblur='mayor()'value=0><br><br>";
}
document.getElementById("divuno").innerHTML=strcadena;
}
function mayor()
{
var mayor=0;
for(i=0; i<10; i++)
{
if(parseInt(document.forms["form1"]["texto"+i].value) > parseInt(mayor))
mayor= parseInt( document.forms["form1"]["texto"+i].value);
}
alert(mayor);
}
</script>
</html>
<html>
<head>
<title>funcion generar y mostrar el mayor</title>
</head>
<body bgcolor="CCFFFF" onload="generar()">
<form id="form1"name="form1">
<div id="divuno">
</form>
</body>
<script type="text/javascript">
function generar()
{
var strcadena="";
for(i=0;i<10;i++)
{
strcadena+="<input type ='text' id='texto"+i+"' name='texto"+i+"'onblur='mayor()'value=0><br><br>";
}
document.getElementById("divuno").innerHTML=strcadena;
}
function mayor()
{
var mayor=0;
for(i=0; i<10; i++)
{
if(parseInt(document.forms["form1"]["texto"+i].value) > parseInt(mayor))
mayor= parseInt( document.forms["form1"]["texto"+i].value);
}
alert(mayor);
}
</script>
</html>
Suscribirse a:
Comentarios (Atom)