You are on page 1of 11

<?

/***VARIABLES POR GET ***/ $numero = count($_GET); $tags = array_keys($_GET);// obtiene los nombres de las varibles $valores = array_values($_GET);// obtiene los valores de las varibles

// crea las variables y les asigna el valor for($i=0;$i<$numero;$i++){ $$tags[$i]=$valores[$i]; } /***VARIABLES POR POST ***/ $numero2 = count($_POST); $tags2 = array_keys($_POST); // obtiene los nombres de las varibles $valores2 = array_values($_POST);// obtiene los valores de las varibles // crea las variables y les asigna el valor for($i=0;$i<$numero2;$i++){ $$tags2[$i]=$valores2[$i]; } /* ahora solo hay que llamar las variables por su nombre ej: http://misitio.com/estearchivo.php?usuario=cristalab&password=sangre

para verlas solo pones la variable por su nombre echo "nombre de usuario: ".$usuario."<br> password: ".$password; en vez de usar $_GET['usuario'] y $_GET['password'] */ ?>

valida que el campo sea numrico pero no me permite utilizar el tabulador si alguien podria explicarme donde hacer el camiop para que me lo permita. de antemano gracias ! function validar(e) { // 1 /* * d un dgito. Equivale a [0-9] * D cualquier caracter que no sea un dgito. * w Cualquier caracter alfanumrico. Equivalente a [a-zA-Z0-9_]. * W cualquier caracter no alfanumrico

* s espacio * t tabulador */ tecla = (document.all) ? e.keyCode : e.which; // 2 if ((tecla==8)||(tecla==9)) return true; // 3 patron = /^([0-9t])*$/; // 4 te = String.fromCharCode(tecla); // 5 return patron.test(te); // 6 } EJEMPLOS <html> <head> <script type="text/javascript"> function show_alert() { alert("Hello! I am an alert box!"); } </script> </head> <body> <input type="button" onclick="show_alert()" value="Show alert box" /> </body> </html> EJEM 2 <html> <head> <script type="text/javascript"> function show_confirm() { var r=confirm("Press a button!"); if (r==true) { alert("You pressed OK!"); } else { alert("You pressed Cancel!"); } } </script> </head> <body> <input type="button" onclick="show_confirm()" value="Show a confirm box" />

</body> </html> EJEM 3 <html> <head> <script type="text/javascript"> function show_prompt() { var name=prompt("Please enter your name","Harry Potter"); if (name!=null && name!="") { document.write("Hello " + name + "! How are you today?"); } } </script> </head> <body> <input type="button" onclick="show_prompt()" value="Show prompt box" /> </body> </html> FUNCIN CON PARAMETRO <html> <head> <script type="text/javascript"> function myfunction(txt) { alert(txt); } </script> </head> <body> <form> <input type="button" onclick="myfunction('Hello')" value="Call function"> </form> <p>By pressing the button above, a function will be called with "Hello" as a parameter. The function will alert the parameter.</p> </body> </html> FUNCIN ARGUMENTOS 2 <html> <head> <script type="text/javascript"> function myfunction(txt) { alert(txt);

} </script> </head> <body> <form> <input type="button" onclick="myfunction('Good Morning!')" value="In the Morning"> <input type="button" onclick="myfunction('Good Evening!')" value="In the Evening"> </form> <p> When you click on one of the buttons, a function will be called. The function will alert the argument that is passed to it. </p> </body> </html> FUNCIN CON ARGUMENTOS QUE DEVUELVEN UN VALOR <html> <head> <script type="text/javascript"> function product(a,b) { return a*b; } </script> </head> <body> <script type="text/javascript"> document.write(product(4,3)); </script> <p>The script in the body section calls a function with two parameters (4 and 3).</p> <p>The function will return the product of these two parameters.</p> </body> </html> SWITCH <html> <body> <script type="text/javascript"> var d = new Date(); theDay=d.getDay(); switch (theDay)

{ case 5: document.write("<b>Finally Friday</b>"); break; case 6: document.write("<b>Super Saturday</b>"); break; case 0: document.write("<b>Sleepy Sunday</b>"); break; default: document.write("<b>I'm really looking forward to this weekend!</b>"); } </script> <p>This JavaScript will generate a different greeting based on what day it is. Note that Sunday=0, Monday=1, Tuesday=2, etc.</p> </body> </html> FOR LOOP <html> <body> <script type="text/javascript"> for (i = 0; i <= 5; i++) { document.write("The number is " + i); document.write("<br />"); } </script> <p>Explanation:</p> <p>This for loop starts with i=0.</p> <p>As long as <b>i</b> is less than, or equal to 5, the loop will continue to run.</p> <p><b>i</b> will increase by 1 each time the loop runs.</p> </body> </html> HEADERS <html> <body> <script type="text/javascript"> for (i = 1; i <= 6; i++) { document.write("<h" + i + ">This is heading " + i);

document.write("</h" + i + ">"); } </script> </body> </html> WHILE <html> <body> <script type="text/javascript"> i=0; while (i<=5) { document.write("The number is " + i); document.write("<br />"); i++; } </script> <p>Explanation:</p> <p><b>i</b> is equal to 0.</p> <p>While <b>i</b> is less than , or equal to, 5, the loop will continue to run.</p> <p><b>i</b> will increase by 1 each time the loop runs.</p> </body> </html> DO WHILE <html> <body> <script type="text/javascript"> i = 0; do { document.write("The number is " + i); document.write("<br />"); i++; } while (i <= 5) </script> <p>Explanation:</p> <p><b>i</b> equal to 0.</p> <p>The loop will run</p> <p><b>i</b> will increase by 1 each time the loop runs.</p> <p>While <b>i</b> is less than , or equal to, 5, the loop will continue to run.</p>

</body> </html> BREAK Y CONTINUE <html> <body> <script type="text/javascript"> var i=0; for (i=0;i<=10;i++) { if (i==3) { continue; } document.write("The number is " + i); document.write("<br />"); } </script> <p>Explanation: The loop will break the current loop and continue with the next value when i=3.</p> </body> </html> FOR Y LOOP <html> <body> <script type="text/javascript"> var x; var mycars = new Array(); mycars[0] = "Saab"; mycars[1] = "Volvo"; mycars[2] = "BMW"; for (x in mycars) { document.write(mycars[x] + "<br />"); } </script> </body> </html> EXCEPTIONS <html> <head> <script type="text/javascript"> var txt=""; function message() { try {

adddlert("Welcome guest!"); } catch(err) { txt="There was an error on this page.\n\n"; txt+="Error description: " + err.description + "\n\n"; txt+="Click OK to continue.\n\n"; alert(txt); } } </script> </head> <body> <input type="button" value="View message" onclick="message()" /> </body> </html> EXCEPTION 2 <html> <head> <script type="text/javascript"> var txt=""; function message() { try { adddlert("Welcome guest!"); } catch(err) { txt="There was an error on this page.\n\n"; txt+="Click OK to continue viewing this page,\n"; txt+="or Cancel to return to the home page.\n\n"; if(!confirm(txt)) { document.location.href="http://www.w3schools.com/"; } } } </script> </head> <body> <input type="button" value="View message" onclick="message()" /> </body> </html>
EXCEPTION 3 <html> <head>

<script type="text/javascript"> onerror=handleErr; var txt=""; function handleErr(msg,url,l) { txt="There was an error on this page.\n\n"; txt+="Error: " + msg + "\n"; txt+="URL: " + url + "\n"; txt+="Line: " + l + "\n\n"; txt+="Click OK to continue.\n\n"; alert(txt); return true; } function message() { adddlert("Welcome guest!"); } </script> </head> <body> <input type="button" value="View message" onclick="message()" /> </body> </html> TIMMING 3 SEGUNDOS <html> <head> <script type="text/javascript"> function timedMsg() { var t=setTimeout("alert('I am displayed after 3 seconds!')",3000); } </script> </head> <body> <form> <input type="button" value="Display alert box!" onClick="timedMsg()" /> </form> </body> </html> CREAR DIRECYAMENTE UNA INSTANCIA DE OBJETO <html> <body> <script type="text/javascript"> personObj=new Object(); personObj.firstname="John"; personObj.lastname="Doe"; personObj.age=50; personObj.eyecolor="blue";

John is 50 years old.

document.write(personObj.firstname + " is " + personObj.age + " years old."); </script> </body>

</html> CREAR UN TEMPLATE PARA UN OBJETO <html> <body> <script type="text/javascript"> function person(firstname,lastname,age,eyecolor) { this.firstname=firstname; this.lastname=lastname; this.age=age; this.eyecolor=eyecolor; } myFather=new person("John","Doe",50,"blue"); document.write(myFather.firstname + " is " + myFather.age + " years old."); </script> </body> </html> REDONDEO <html> <body> <script type="text/javascript"> document.write(Math.round(0.60) + "<br />"); document.write(Math.round(0.50) + "<br />"); document.write(Math.round(0.49) + "<br />"); document.write(Math.round(-4.40) + "<br />"); document.write(Math.round(-4.60)); </script> </body> </html> LONGITUD DE UNA CADENA <script type="text/javascript"> var txt = "Hello World!"; document.write(txt.length); </script> VALIDAR CLAVE La funcin para validar contraseas Funcin en PHP ctype_alnum(), que recibe un string y devuelve TRUE si slo encontr nmeros y letras en esa cadena y FALSE si encontr otro tipo de caracteres. <html> <head> <title>Validar Password</title> </head> <body> <? function validar_clave($clave,&$error_clave){ if(strlen($clave) < 6){

John is 50 years old.

$error_clave = "La clave debe tener al menos 6 caracteres"; return false; } if(strlen($clave) > 16){ $error_clave = "La clave no puede tener ms de 16 caracteres"; return false; } if (!preg_match('`[a-z]`',$clave)){ $error_clave = "La clave debe tener al menos una letra minscula"; return false; } if (!preg_match('`[A-Z]`',$clave)){ $error_clave = "La clave debe tener al menos una letra mayscula"; return false; } if (!preg_match('`[0-9]`',$clave)){ $error_clave = "La clave debe tener al menos un caracter numrico"; return false; } $error_clave = ""; return true; } if ($_POST){ $error_encontrado=""; if (validar_clave($_POST["clave"], $error_encontrado)){ echo "PASSWORD VLIDO"; }else{ echo "PASSWORD NO VLIDO: " . $error_encontrado; } } ?> <P> <form action="validar-password.php" method="post"> Escribe una clave: <input type=password name="clave"> <input type="submit" value="Enviar"> </form> </body> </html>

Valor de campos text alert(document.MiFormulario.elements['valor'+a].value);

You might also like