Ultrashock Forums > Flash > ActionScript
[AS3] RegExp

You are currently viewing our website as a guest which gives you limited access to forums, files and other resources.

Click here to join now for free, and start interacting with our members, download files and much more!

Click here if you are looking for our Flash files and other professional assets.
 
Post Reply | View first unread | Rate Thread Search this Thread | Thread Tools | Display Modes

#1
Bookmark and Share!
[AS3] RegExp
Old 2008-02-18

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:

ActionScript Code:
  1. function validateEmail( email:String ):Boolean
  2. {
  3.     var i:int = -1;
  4.     var n:int = email.length;
  5.    
  6.     if( n <= 6 )
  7.     {
  8.         return false;
  9.     }
  10.  
  11.     var invalidChar:String = "~^*|,\":<>[]{}`\';()&$#%";
  12.    
  13.     while( ++ i < n )
  14.     {
  15.         if( invalidChar.indexOf( email.charAt( i ) ) != -1 )
  16.         {
  17.             return false;
  18.         }
  19.     }
  20.    
  21.     return true;
  22. }
I'm going to eat your brain and gain your knowledge.
postbit arrow 4 comments | 1742 views postbit arrow Reply: with Quote   
Registered User
Isocase is offline
seperator
Posts: 1,441
2006-11-03
Age: 28
Isocase lives in United States
Isocase's Avatar
seperator

Ultrashock Member Comments:
Isocase's Avatar Isocase Isocase is offline Isocase lives in United States 2008-02-18 #2 Old  
Did some research and I was finally able to find information on wikipedia. Here is the URL if anyone ever needs to know this information

http://en.wikipedia.org/wiki/E-mail_address
Reply With Quote  
Fernando's Avatar Fernando Fernando is offline Moderator Fernando lives in Peru 2008-02-18 #3 Old  
ActionScript Code:
  1. function isValidEmail(email:String):Boolean {
  2.     var emailExpression:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
  3.     return emailExpression.test(email);
  4. }

ActionScript Code:
  1. trace (isValidEmail("user@ultrashock.com")); // true
  2. trace (isValidEmail("test@@tester.com")); // false
  3.  
Reply With Quote  
Isocase's Avatar Isocase Isocase is offline Isocase lives in United States 2008-02-20 #4 Old  
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?
Reply With Quote  
Fernando's Avatar Fernando Fernando is offline Moderator Fernando lives in Peru 2008-02-20 #5 Old  
RegExp is a hell lot faster than a substring way of doing smth.
Reply With Quote  
Thread Tools
Display Modes Rate This Thread
Rate This Thread: