![]() |
![]() |
||||||
|
|||||||
| Tags: email, expression, regular, stringmatch |
![]() |
|
|||
|
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; } |
| Sponsored Links |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise