Ver Mensaje Individual
  #5 (permalink)  
Antiguo 29/03/2006, 14:15
Avatar de luistar
luistar
 
Fecha de Ingreso: marzo-2005
Ubicación: Argentina
Mensajes: 939
Antigüedad: 19 años, 1 mes
Puntos: 0
Código:
//solo verifica que contenga un punto y una arroba
String.prototype.pareceEmail = function() :Boolean{
	return this.indexOf("@") != -1 && this.indexOf(".") != -1;
}

//ejemplos de su uso
var correos:Array = new Array('[email protected]','yoni.pache@co','yoni.@pacheco','yonipache.co','yoni@pacheco');
trace("PARECE EMAIL\n----------------------------------------------");
for(var i in correos) trace(correos[i]+' -> '+correos[i].pareceEmail());
OTRA MANERA
Código:
///////////////////////////////////////-------------------------->
//credits:
// 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);

//ejemplos
var mas_correos:Array = new Array("[email protected]","[email protected]","[email protected]","joe@somewherecom","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected]","[email protected].","[email protected]","[email protected]","[email protected]","joe@[email protected]","[email protected]","@somewhere.com");
trace("\nES EMAIL\n----------------------------------------------");
for(var i in mas_correos) trace(mas_correos[i]+' -> '+mas_correos[i].esEmail());

stop();
esto último parece mostruoso, pero en la siguiente versión de ActionSctrip se podrá hacer en una línea usando con expresiones regulares

para usarlo solo tienes que llamarlo como método de una cadena
ejemp para verificar si el texto del campo de texto: 'email_txt' tiene formato de email

boton.onRelease = function(){
trace(email_txt.text.pareceEmail());
trace(email_txt.text.esEmail());
}

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