Adobe Dreamweaver Forums



Last 10 THreads :         Live stream player (Last Post : noobie_here - Replies : 0 - Views : 1 )           »          cfloop within a cfif tag (Last Post : Azadi - Replies : 2 - Views : 3 )           »          Making constraints on a symbol... (Last Post : sirkibble2 - Replies : 0 - Views : 1 )           »          Creating a boundry in the stage... (Last Post : fazstp - Replies : 2 - Views : 3 )           »          Director or Flash? (Last Post : Sean Wilson - Replies : 1 - Views : 2 )           »          DW8 Activation not working (Last Post : moonliner - Replies : 0 - Views : 1 )           »          Re: Mouse capture won't activate (Last Post : robertnagle - Replies : 0 - Views : 1 )           »          help! my FB3 has gone insane! (Last Post : peteandrus - Replies : 0 - Views : 1 )           »          help! my FB3 has gone insane! (Last Post : peteandrus - Replies : 0 - Views : 1 )           »          How come the html is being displayed, and not the link (Last Post : Skaterstu - Replies : 0 - Views : 1 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Other Macromedia/Adobe Products > Flex
 
Tags: , , ,



Reply
  #1 (permalink)  
Old 09-05-2008, 05:36 PM
uadrive
 
Posts: n/a
Diggs:
Default Email Regular Expression with a String.Match()

I'm currently using a RichTextEditor for a user to build HTML for a site.
However, I want the application to scan for emails and encode them so they are
protected from spam bots when they go to the live site. I've written a regular
expression to find an email and it seems to work, but it only returns one email
at a time from the string. I have had to revert to a while loop to traverse
the string until I'm satisfied. I don't particularly like that method and
would like to just do one String.match() query to retrieve all of the emails.
Can anyone see something here that I'm missing?



private function encodeHTML(event:Event):void
{
// grab the text
var result:String = editor.htmlText;

// create the pattern to search for an email
//var emailPattern:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
var emailPattern:RegExp = /[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]+/;
var emails:Array = result.match(emailPattern);

while(emails != null) {
for(var i:int = 0; i < emails.length; i++)
{
// encode the email and replace it with the encoded email
var encodedEmail:String = encodeEmail(emails[i]);
var replaceExp:RegExp = new RegExp(emails[i], "");

result = result.replace(replaceExp, encodedEmail);
}

emails = result.match(emailPattern);
}

results.text = result;
}



Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 09-05-2008, 06:42 PM
VarioPegged
 
Posts: n/a
Diggs:
Default Re: Email Regular Expression with a String.Match()

Try adding the global flag (g):

....
var emailPattern:RegExp = /[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]+/g;
....

TS

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 02:37 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Inactive Reminders By Mished.co.uk