Posts Tagged ‘email’

Validar email con RegExp (en dos líneas)

Un ejemplo de cómo validar un email usando la clase de expresiones regulares de ActionScript 3:

function isValidEmail(email:String):Boolean {
var emailExpression:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
return emailExpression.test(email);
}

Top level RegExp

isEmail String prototype

Este prototipo es uno de tantos que valida emails:

String.prototype.isEmail = function() {
if (!this) {
return false;
}
var iChars = "*|,\":<>[]{}`’;()&$#% ";
for (var i = 0; i<this.length; i++) {
if (iChars.indexOf(this.charAt(i)) != -1) {
return false;
}
}
if (this.indexOf("@") == -1) {
return false;
}
if (this.indexOf(".") == -1) {
return false;
}
return true;
};
//Uso:
mail="jaja@pua.es";
trace(mail.isEmail());