Example Name: EmailAddress.asr
Language: ServerSide ActionScript
Version: 1.0.0
Code:
function EmailAddressException(address) {
this.value = address;
this.message = " is not a valid email address";
this.toString = function() {
return this.value + this.message;
}
}
function EmailAddress(email, name) {
var theExpression = /^[A-Za-z0-9\_\-]+\@[A-Za-z0-9\_\-]+.*\.\w{2,6}$/;
if(theExpression.test(email)) {
this.address = email;
this.name = name;
}else{
throw new EmailAddressException(email);
}
}
function validateEmail(email, name) {
var myEmailObject;
try {
myEmailObject = new EmailAddress(email, name);
} catch(e) {
if(e instanceof EmailAddressException) {
return e.toString();
}else{
return "Undefined error";
}
}
return myEmailObject;
}
Download code text
Download chapter example files