Flash / Flex / ActionScript/Regular Expressions/Email Address
Determining whether a string contains a valid email address format
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var sEmail:String = new String("someone@someserver.ru");
var bValidEmail:Boolean = true;
var nAmpIndex:int = sEmail.indexOf("@");
var nDotIndex:int = sEmail.lastIndexOf(".");
if(nAmpIndex == -1 || nDotIndex == -1) {
bValidEmail = false;
}
if(!(nAmpIndex > 0)) {
bValidEmail = false;
}
if(!(nDotIndex > nAmpIndex)) {
bValidEmail = false;
}
if(!(nDotIndex < sEmail.length - 1) || !(nDotIndex > nAmpIndex + 1)) {
bValidEmail = false;
}
trace(bValidEmail);
}
}
}
Using a regular expression to determine whether a string contains a valid email address format
package{
import flash.display.Sprite;
public class Main extends Sprite{
public function Main(){
var sEmail:String = new String("someone@someserver.ru");
var reEmail:RegExp = new RegExp("^([\\w\\-\\.]+)@(([\\w ;\\-]{2,}\\.)+[\\w\\-]{2,3})$");
trace(reEmail.test(sEmail));
}
}
}