Schemaphic Systems Blog

Sharing experiences in Flash, Flex and AIR

Check for valid email

leave a comment »

/**********************************************/

/*
* Checks for a valid email address
*
* @param: value:String – email address
* @returns: Boolean value – true if valid
*/
public function isValidEmail(str:String):Boolean
{
var at:String = “@”;
var dot:String = “.”;
var lat:int = str.indexOf(at);
var lstr:int = str.length;
var ldot:int = str.indexOf(dot);
if (str.indexOf(at) == -1) {
//trace(“Invalid E-mail ID”);
return false;
}
if (str.indexOf(at) == -1 || str.indexOf(at) == 0 || str.indexOf(at) == lstr) {
//trace(“Invalid E-mail ID”);
return false;
}
if (str.indexOf(dot) == -1 || str.indexOf(dot) == 0 || str.indexOf(dot) == lstr) {
//trace(“Invalid E-mail ID”);
return false;
}
if (str.indexOf(at,(lat+1))!=-1) {
//trace(“Invalid E-mail ID”);
return false;
}
if (str.substring(lat-1, lat) == dot || str.substring(lat+1,lat+2) == dot) {
//trace(“Invalid E-mail ID”);
return false;
}
if (str.indexOf(dot,(lat+2)) == -1) {
//trace(“Invalid E-mail ID”);
return false;
}
if (str.lastIndexOf(dot) == (lstr-1)) {
//trace(“Invalid E-mail ID – dot at end”);
return false;
}
if (str.indexOf(” “) != -1) {
//trace(“Invalid E-mail ID”);
return false;
}
return true;
}

/*
* checks for a valid email address using regular expression
*
* @param: value:String – email address
* @returns: Boolean value – true if valid
*/
public function isValidEmailWithRegExp(str:String):Boolean
{
var emailExpression : RegExp = ~/^[\w-\.]{2,}@[ÅÄÖåäö\w-\.]{2,}\.[a-z]{2,6}$/i;
return emailExpression.match( str );
}

Advertisements

Written by Deepanjan Das

June 13, 2010 at 7:09 AM

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: