Ver Mensaje Individual
  #7 (permalink)  
Antiguo 29/03/2006, 16:48
Avatar de luistar
luistar
 
Fecha de Ingreso: marzo-2005
Ubicación: Argentina
Mensajes: 939
Antigüedad: 19 años, 1 mes
Puntos: 0
por medio del teclado? supongo que se refería a eventos de teclado

aquí te pongo un ejemplo de validar email
el texto se valida:
- a medida que escribes en el TextInput
- cuando presinas en el botón
- cuando presionas ENTER

no te pongo el .fla porque pesa como 600kb ya que usa componentes y ya casi me quedo sin espacio xD

este es el código que hace funcionar todo (es solo aplicar la funciones que te mencioné anteriormente)

Código:
///////////////////////////////////////-------------------------->
// String.isEmail Method v2.0
// by Jonas Galvez ([email protected])
// please report bugs =)

String.prototype.esEmail = function():Boolean {
    var ref = arguments.callee;
    if(this.indexOf('@') == -1 || this.indexOf('.') == -1) return false;
    if(!isNaN(this.charAt(0))) return false;
    var email, user, domain, user_dots, domain_dots;
    if((email = this.split('@')).length == 2) { 
        if((domain = email[1]).split('.').pop().length > 3) return false;
        if((user = email[0]).indexOf('.') && domain.indexOf('.')) {     
            if(domain.lastIndexOf('.') > domain.length-3) return false;
            for(var c, t, i = (user_dots = user.split('.')).length; i--;) {
                c = user_dots[i]; t = !ref.$_text.call(c, '-', '.', '_');
                if(t || !isNaN(c)) return false;
            };
            for(var c, t, i = (domain_dots = domain.split('.')).length; i--;) {
                c = domain_dots[i]; t = !ref.$_text.call(c, '-', '.');
                if(t || !isNaN(c)) return false;
            };
        } else return false;
    } else return false;
    return true;
};
String.prototype.esEmail.$_punctuation = function() {
    if(this == "") return false;
    for(var i = arguments.length; i--;) {
        if(this.indexOf(arguments[i]) == 0) return false;
        if(this.indexOf(arguments[i]) == this.length-1) return false;
    };
    return true;
};
String.prototype.esEmail.$_text = function() {
    var ref = arguments.caller;
    if(!ref.$_punctuation.apply(this, arguments)) return false;
    var others = arguments; var checkOthers = function(str) {
        for(var i = others.length; i--;) if(str == others[i]) return true;
        return false;
    };
    for(var c, alpha, num, i = this.length; i--;) {
        c = this.charAt(i).toLowerCase();
        alpha = (c <= "z") && (c >= "a");
        num = (c <= "9") && (c >= "0");
        if(!alpha && !num && !checkOthers(c)) return false;
    };
    return true;
}; 
ASSetPropFlags(String.prototype, "isEmail", 1);
//-------------------------->

var al_escribir:Object = new Object();
al_escribir.change = function(objeto:Object){
	valida_txt.text = objeto.target.text.esEmail() ? 'El correo es válido' : 'formato de email INCORRECTO';
}
correo.addEventListener('change',al_escribir);

var al_enviar:Object = new Object();
al_enviar.keyUp = function(objeto:Object){
	if(objeto.code == 13){ //tecla ENTER
		var alerta:String = objeto.target.text.esEmail() ? 'El correo es válido, estamos enviado el mensaje...' : 'formato de email INCORRECTO, verifique bien...';
		getURL ("javascript:alert('"+alerta+"');");
		trace(alerta);
	}
}
correo.addEventListener('keyUp',al_enviar);

var al_clickar:Object = new Object();
al_clickar.click = function(){
	var alerta:String = correo.text.esEmail() ? 'El correo es válido, estamos enviado el mensaje...' : 'formato de email INCORRECTO, verifique bien...';
	getURL ("javascript:alert('"+alerta+"');");
	trace(alerta);
}
enviar.addEventListener('click',al_clickar);

stop();
el TextInput tiene nombre de instancia 'correo'
el Button, nombre de instancia 'enviar'
y el campo te texto -> 'valida_txt'

parece complicado? xD
lo es un poco, pero es el camino correcto

:D
__________________
Si digo que soy mentiroso. ¿Lo soy?