Email Validation

6 02 2008

Here is a base email validation class for AS2

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”)
}

Advertisements

Actions

Information

One response

30 06 2013
Rennruessel

Very helpful – thanks a lot!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: