Retroceder   Foros del Web > Programación para sitios web > Javascript

Respuesta
 
Herramientas Desplegado
Antiguo 30-jun-2008, 14:52   #271 (permalink)
Adler está en el buen camino
 
Avatar de Adler
 
Fecha de Ingreso: diciembre-2006
Mensajes: 572
Respuesta: Validar E-Mail

Código PHP:
function vMail(ce) {
var 
okemce.email.value;

var 
localOK = /^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$/;
var ipOK = /^[?[0-9.]+]?$/;
var 
dominoOK = /^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$/;

// El email consta de dos partes dividas por @
var email_array okem.split('@');

if (
email_array.length || email_array.length 2) {
alert("La dirección de email 1  ("email_array.length +") no es válida.");
       
document.forms.sendmail.email.focus();
       return (
false);
    }

// Incorrecto número de caracteres en alguna de las dos partes
if (email_array[0].length  || email_array[1].length  1) {
alert("La dirección de email 2 ("email_array[0].length +") -- ("email_array[1].length +") no es válida.");
       
document.forms.sendmail.email.focus();
       return (
false);
    }

var 
local_array email_array[0].split('.');
for (
0local_array.lengthi++)
{
if (!
localOK.test(local_array[i])) {
alert("La dirección de email 3 ("local_array[i] +") no es válida.");
       
document.forms.sendmail.email.focus();
       return (
false);
    }
}

// Se revisa si el dominio es una IP. Si no, debe ser un nombre de dominio válido
if (!ipOK.test(okem)) {

var 
dominio_array email_array[1].split('.');
// Incorrecto número de secciones por exceso o defecto para ser un dominio
if (dominio_array.length || dominio_array.length 3) {
alert("La dirección de email 4 ("dominio_array.length +") no es válida.");
       
document.forms.sendmail.email.focus();
       return (
false);
    }

for (
0dominio_array.lengthi++)
{
if (!
dominoOK.test(dominio_array[i])) {
alert("La dirección de email 5 ("dominio_array[i] +") no es válida.");
       
document.forms.sendmail.email.focus();
       return (
false);
    }
        }
}
else
return (
true)

Mismo código en php

Mismo código en asp
__________________
Nunca has tenido un sábado sangriento??
Adler está desconectado   Responder Citando
Antiguo 27-jul-2008, 01:57   #272 (permalink)
andrewp está en el buen camino
 
Avatar de andrewp
 
Fecha de Ingreso: agosto-2003
Ubicación: Barcelona
Mensajes: 873
Respuesta: FAQs JavaScript

Pregunta: Cómo puedo validar un grupo de radio buttons?
Respuesta: Respuesta complementada por XBX:

En el header deberías incluir el siguiente código:

Código PHP:
<script language="javascript">
function 
query_validator(){
    var 
isOneChecked false;
    for (var 
i=0document.form.grupo.lengthi++)
    {
         if(
document.form.grupo[i].checked){
            
isOneChecked true;
            break;
         }
    }

    if (!
isOneChecked) {
        
alert('Por favor, seleccione una respuesta');
         return(
false);
    }
}
</script> 
En el body de tu página debes inclmuír la siguiente acción en el inicio del formulario:

Código PHP:
<form name="form3" action="respuestas.php" method="post" onsubmit="return query_validator();">
... 
Aqui el resto de tu codigo con el grupo de radio buttons incluido ...
</
form
__________________
Andrew :P

Última edición por andrewp; 27-jul-2008 a las 01:59. Razón: Inclusión de nueva linea de código
andrewp está desconectado   Responder Citando
Antiguo 05-ago-2008, 11:39   #273 (permalink)
marcopoloaz06 ha deshabilitado el karma
 
Avatar de marcopoloaz06
 
Fecha de Ingreso: julio-2007
Ubicación: Metro Neza,Edo.Méx
Mensajes: 296
Enviar un mensaje por MSN a marcopoloaz06
Sonrisa 274.- PUNTEROS en un Array

P:¿ Cómo usar las funciones de PHP current(),next(),prev(),end(),reset(), en JavaScript ?
R: [EJEMPLO]

asi:
Código HTML:
<script type="text/javascript">
(function(){
// PUNTEROS ARRAY
Array.prototype.currentNum = 0;
Array.prototype.current = function(){
    return this[ this.currentNum ];
};
Array.prototype.next = function(){
    return this.currentNum+1<this.length ? this[ ++this.currentNum ] : false;
};
Array.prototype.prev = function(){
    return this.currentNum-1>0 ? this[ --this.currentNum ] : false;
};
Array.prototype.end = function(){
    return this.length>0 ? this[ this.currentNum = this.length-1 ] : false;
};
Array.prototype.reset = function(){
    return this[ this.currentNum = 0 ];
};
})();
</script>
pueden ver el ejemplo

Saludos
:]
__________________
ya me regañaron :[
http://userscripts.org/scripts/show/20617
Haciendo juego en Javascript 75%

Última edición por marcopoloaz06; 01-sep-2008 a las 11:15.
marcopoloaz06 está desconectado   Responder Citando
Antiguo 13-ago-2008, 22:58   #274 (permalink)
marcopoloaz06 ha deshabilitado el karma
 
Avatar de marcopoloaz06
 
Fecha de Ingreso: julio-2007
Ubicación: Metro Neza,Edo.Méx
Mensajes: 296
Enviar un mensaje por MSN a marcopoloaz06
Cool 275.- ¿Cómo hacer un Enum?

P:¿Cómo hacer un Enum como en otros lenguajes de programación?
R: asi:

Código PHP:
    function Enum(nombRevaloRes){
        
window[nombRe] = {};
        for(var 
i=j=0;i<valoRes.length;i++,j++){
            var 
valoRes[i].split("-");
            
window[nombRe][( s.length>) ? s[0] : valoRes[i] ] = ( s.length>) ? j=Numbers[1] ) : j;
        }
    };
    
Enum.isDefined = function( Enumval ){
        for( 
x in Enum ){
            if( 
x==val ) return Enum[x];
        }
        return -
1;
    };
    
// EJEMPLOS
    
Enum"maRco", ["a""as""asd""asdf""asdfg""asdfgh"] );
     
maRco = {a0, as: 1asd2asdf3asdfg4asdfgh5};
    
Enum"pOlo", ["z-1""y""x"] )
     
pOlo = {z1y2x3};
    
Enum"aZ", ["x-1""xd""xD-10""XD""Xd-20""d"] );
     
aZ = {x1xd2xD10XD11Xd20d:21};
    
Enum.isDefinedaZ"XD" );
     
// return 11; 
Saludos &
adios...
;]
__________________
ya me regañaron :[
http://userscripts.org/scripts/show/20617
Haciendo juego en Javascript 75%

Última edición por marcopoloaz06; 14-ago-2008 a las 12:22.
marcopoloaz06 está desconectado   Responder Citando
Antiguo 07-sep-2008, 15:53   #275 (permalink)
Colaborador
Panino5001 llegará a ser famoso muy prontoPanino5001 llegará a ser famoso muy prontoPanino5001 llegará a ser famoso muy prontoPanino5001 llegará a ser famoso muy pronto
 
Avatar de Panino5001
 
Fecha de Ingreso: mayo-2004
Ubicación: Buenos Aires
Mensajes: 1.709
Respuesta: FAQs JavaScript

P: Cómo logar un efecto espejo con javascript?
R: Usando Canvas para los navegadores estandar y un filtro propietario para explorer. Ejemplo . Código del ejemplo
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>test</title>
<
script>
function 
reflejo (contenedorimagen) {
        var 
ref false;
        if (
document.createElement("canvas").getContext) {
            
/* ---- canvas ---- */
            
ref document.createElement("canvas");
            
ref.width imagen.width;
            
ref.height imagen.height;
            var 
context ref.getContext("2d");
            
context.translate(0imagen.height);
            
context.scale(1,-1);
            
context.drawImage(imagen00imagen.widthimagen.height);
            
ref.style.opacity '0.35';
        } else {
            
/* ---- DXImageTransform ---- */
            
ref=document.createElement('img');
            
ref.src=imagen.src;
            
ref.style.filter 'flipv progid:DXImageTransform.Microsoft.Alpha(opacity=50, style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy=' imagen.height ')';
        
ref.widthimagen.width;
        
ref.heightimagen.height;
        }
        
ref.style.position 'absolute';
        
ref.style.left0;
        
ref.style.topimagen.height+'px'
        
contenedor.appendChild(ref);
    }
window.onload=function(){
    
reflejo(document.getElementById('pp'), document.getElementById('ll'));
}
</script>
</head>

<body>
<div id="pp" style="position:relative"><img id="ll" src="5.jpg" width="180" height="144" /></div>
</body>
</html> 
Si bien el efecto está bastante logrado, podemos mejorarlo haciendo que el resultado en navegadores estandar se parezca más al que obtenemos en Explorer, aplicando gradientes como hace este último en su filtro. Este sería el resultado final.
Y este el código utilizado:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>test</title>
<
script>
function 
reflejo (contenedorimagen) {
        var 
ref false;
        if (
document.createElement("canvas").getContext) {
            
/* ---- canvas ---- */
            
ref document.createElement("canvas");
            
ref.width imagen.width;
            
ref.height imagen.height;
            var 
context ref.getContext("2d");
            
context.translate(0imagen.height);
            
context.scale(1,-1);
            
context.drawImage(imagen00imagen.widthimagen.height);
            
context.globalCompositeOperation "destination-out";
            var 
gradient context.createLinearGradient(000imagen.height);
            
gradient.addColorStop(0"rgba(255, 255, 255, 1.0)");
            
gradient.addColorStop(1"rgba(255, 255, 255, 0.1)");
            
context.fillStyle gradient;
            
context.fillRect(0,0,imagen.widthimagen.height);
        } else {
            
/* ---- DXImageTransform ---- */
            
ref=document.createElement('img');
            
ref.src=imagen.src;
            
ref.style.filter 'flipv progid:DXImageTransform.Microsoft.Alpha(opacity=50, style=1, finishOpacity=0, startx=0, starty=0, finishx=0, finishy=' imagen.height ')';
        
ref.widthimagen.width;
        
ref.heightimagen.height;
        }
        
ref.style.position 'absolute';
        
ref.style.left0;
        
ref.style.topimagen.height+'px'
        
contenedor.appendChild(ref);
    }
window.onload=function(){
    
reflejo(document.getElementById('pp'), document.getElementById('ll'));
}
</script>
</head>

<body>
<div id="pp" style="position:relative"><img id="ll" src="5.jpg" width="180" height="144" /></div>
</body>
</html> 
(Probado en Explorer, Safari, Ópera, Firefox y Chrome)

Última edición por Panino5001; 08-sep-2008 a las 20:04.
Panino5001 esta en línea ahora   Responder Citando
Antiguo 07-sep-2008, 16:02   #276 (permalink)
Colaborador
Panino5001 llegará a ser famoso muy prontoPanino5001 llegará a ser famoso muy prontoPanino5001 llegará a ser famoso muy prontoPanino5001 llegará a ser famoso muy pronto
 
Avatar de Panino5001
 
Fecha de Ingreso: mayo-2004
Ubicación: Buenos Aires
Mensajes: 1.709
Respuesta: FAQs JavaScript

P: Se puede rotar una imagen usando javascript?
R: Sí, y más allá del camino chapucero que propuse en este post, la inclusión de soporte para el elemento html estandar llamado canvas en la mayoría de los navegadores modernos, junto a filtros propietarios del único navegador popular que no soporta dicho elemento, nos permiten tranquilamente realizar esta tarea. Ejemplo. Código del ejemplo:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>test</title>
<
script>
function 
rotar(obj,angulo){
    if (
angulo >= 0) {
        var 
rotation Math.PI angulo 180;
    } else {
        var 
rotation Math.PI * (360+angulo) / 180;
    }
    var 
costheta Math.cos(rotation);
    var 
sintheta Math.sin(rotation);
    if (
document.createElement("canvas").getContext) {
    
/* ---- canvas ---- */ 
        
var c=document.createElement('canvas');
        
c.width Math.abs(costheta*obj.width) + Math.abs(sintheta*obj.height);
        
c.style.width c.width+'px';
        
c.height Math.abs(costheta*obj.height) + Math.abs(sintheta*obj.width);
        
c.style.height=c.height+'px';
        
c.id=obj.id;
        
c.style.position='absolute';
        var 
ctx=c.getContext('2d');
        
ctx.save();
        if (
rotation <= Math.PI/2) {
            
ctx.translate(sintheta*obj.height,0);
        } else if (
rotation <= Math.PI) {
            
ctx.translate(c.width,-costheta*obj.height);
        } else if (
rotation <= 1.5*Math.PI) {
            
ctx.translate(-costheta*obj.width,c.height);
        } else {
            
ctx.translate(0,-sintheta*obj.width);
        }
        
ctx.rotate(rotation);
        
ctx.drawImage(obj00obj.widthobj.height);
        
obj.parentNode.replaceChild(c,obj);
        
ctx.restore();
    }else{
    
/* ---- DXImageTransform ---- */
        
obj.style.position='absolute';
        
obj.style.filter="progid:DXImageTransform.Microsoft.Matrix(sizingMethod='auto expand')";
        
obj.filters.item(0).M11 costheta;
        
obj.filters.item(0).M12 = -sintheta;
        
obj.filters.item(0).M21 sintheta;
        
obj.filters.item(0).M22 costheta;
    }
}
window.onload=function(){
    
rotar(document.getElementById('pp'),60);
    
}
</script>
</head>

<body>
<img src="1.jpg" width="180" height="127" />
<div id="ll" style="position:relative; "><img id="pp" src="1.jpg" width="180" height="127" /></div>
</body>
</html> 
(Ejemplo probado en Explorer, Safari, Ópera, Firefox y Chrome)

Última edición por Panino5001; 11-sep-2008 a las 03:13. Razón: optimización
Panino5001 esta en línea ahora   Responder Citando
Antiguo 07-oct-2008, 17:19   #277 (permalink)
Raya2 ha deshabilitado el karma
 
Fecha de Ingreso: noviembre-2007
Mensajes: 12
Respuesta: FAQs JavaScript

P: SOLO PARA CHILE - Validacion del RUT
R: Script siguiente
Lo unico a tener en cuenta es que el RUT debe ingresarse en el formato:
12345678-9
Código del ejemplo:
Código PHP:
function validaRut(rut){
    var 
rutlimpio "";
    for (
i=0rut.lengthi++){
        if ((
rut.charAt(i)!=".") && (rut.charAt(i)!="-"))
            
rutlimpiorutlimpio rut.charAt(i);
    }
    
rut=rutlimpio;
    var 
drut=rut.charAt((rut.length-1));
     var 
dvr='0';
    
suma