If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
I Have just posted up a code snippet that validates general email addresses in AS2. [Update] - Click here for the AS3 Email Validation Code
Full code after the jump.
function validateEmail(emailStr:String) {
var errorCount:Number = 0;
//check to see if there are at least two chars be for the @ symbol
if (emailStr.indexOf("@")<2) {
errorCount++;
}
//check that the @ is not within 2 chars of .
if (emailStr.lastIndexOf(".")<=(emailStr.lastIndexOf("@")+2)) {
errorCount++;
}
//check length eg min aa@bb.cc
if (emailStr.length<8) {
errorCount++;
}
//check there is only one @
if (emailStr.indexOf("@") != emailStr.lastIndexOf("@")) {
errorCount++;
}
// return a T/F to the flash file
if (errorCount == 0) {
return true;
} else {
return false;
}
}
//to use it
if(validateEmail(email.text)){
trace("EMAIL VALID");
}else{
trace("EMAIL NOT VALID")
}
Found this useful? How about buying me a coffee - simply click here.



It’s very useful!
Thank you!
Your script will recognize most common email-adresses, but will filter out a lot of completely valid email adresses, AFAICS.
For instance, a@something.dk, or bob.a@domain.com, which are perfectly legal according to RFC.
Regards
Kristian
@Kristian thanks for the heads up. will look into it