I am trying to write out a RegExp pattern to validate an e-mail. I have googled but can’t seem to find a definite answer but what characters/symbols are not allowed in a valid email address?
Is RegExp the way to go to validate an email format? I started off using the below way, but then started looking into RegExp:
[AS]
function validateEmail( email:String ):Boolean
{
var i:int = -1;
var n:int = email.length;
if( n <= 6 )
{
return false;
}
var invalidChar:String = “~^*|,\”:<>[]{}`\’;()&$#%”;
while( ++ i < n )
{
if( invalidChar.indexOf( email.charAt( i ) ) != -1 )
{
return false;
}
}
return true;
}
[/AS]
[as]function isValidEmail(email:String):Boolean {
var emailExpression:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
return emailExpression.test(email);
}[/as]
[as]trace (isValidEmail(“user@ultrashock.com”)); // true
trace (isValidEmail(“test@@tester.com”)); // false[/as]
- 18 February 2008 05:52 PM
-
Thanks Fernando
I was wondering and did some research but couldn’t find the answer I was looking for. In AS3 how processor intensive is using RegExp compared to using substring or something like that.
Example:
Lets say I am building a form and I want to remove white space after the subject. Would it be best to use a RegExp or just loop through the string until it finds the space then use substring to shorten?
- 20 February 2008 06:50 PM
-
- Log in or join for free to make a comment.


