Copy link to clipboard
Copied
We have clients that we have told not to post their email in a textarea form and they do it anyway. Is there a way to find the email address in the textarea output (public view page) and then ******* or whatever their entire email address before and after the @?? We do not want any of the email showing. Thanks in advance.
You could use a regular expression (where appropriate in the flow of your code) to locate an email address and replace it with the desired characters. Here's a sample:
ReReplaceNoCase( originalString, "^[a-zA-Z_0-9-'\+~]+(\.[a-zA-Z_0-9-'\+~]+)*@([a-zA-Z_0-9-]+\.)+[a-zA-Z]{2,7}$", "*********@******", "ALL" )
This snippet should find any email addresses in the variable originalString and replace it with *********@******.
Hope that helps!
Copy link to clipboard
Copied
You could use a regular expression (where appropriate in the flow of your code) to locate an email address and replace it with the desired characters. Here's a sample:
ReReplaceNoCase( originalString, "^[a-zA-Z_0-9-'\+~]+(\.[a-zA-Z_0-9-'\+~]+)*@([a-zA-Z_0-9-]+\.)+[a-zA-Z]{2,7}$", "*********@******", "ALL" )
This snippet should find any email addresses in the variable originalString and replace it with *********@******.
Hope that helps!
Copy link to clipboard
Copied
Thanks! You rock!
Copy link to clipboard
Copied
Hmmm....the code is still not finding the emails in the output. Any ideas on why this would not work? The output is just a paragraph of data submitted through a textarea form.
#ReReplaceNoCase(data.comments,"^[a-zA-Z_0-9-'\+~]+(\.[a-zA-Z_0-9-'\+~]+)*@([a-zA-Z_0-9-]+\.)+[a-zA-Z]{2,7}$", "*********@******", "ALL")#
Copy link to clipboard
Copied
Could you post or send me a sample of the data.comments text? (Is this from a DB where data is the query and comments the field?). I'd probably have better luck looking at a bit of the code!
Cheers,
Craig
Copy link to clipboard
Copied
Yes, it is a straight output of an NText SQL database field from a query = #data.comments# - no other code. The output may contact several paragraphs. I am just trying to find and mask email addresses placed there so no direct contact can be made.
Copy link to clipboard
Copied
Thanks. Running a few tests now...
Copy link to clipboard
Copied
Okay, this was my bad. I sent you a regexp that I use to validate emails from a form, where the email would be the only text in the string. The regexp had two characters (the first, or ^, and the last, $) that need to be removed. The ^ character looks for a regexp at the start of a string and the $ indicates the end of a string. Removing these characters from the regexp makes it work.
Here's a sample of working code (just tested):
<cfsavecontent variable="comments">
This is my content. It has some text in it. It also has some email addresses in it. One address is myemail@domain.com and another email is from myotheremail@domain.co.uk. Yet another email address would be from a friend and it is athirdemail@gmail.com.
</cfsavecontent>
<cfscript>
cleanContent = ReReplaceNoCase( comments, "[a-zA-Z_0-9-'\+~]+(\.[a-zA-Z_0-9-'\+~]+)*@([a-zA-Z_0-9-]+\.)+[a-zA-Z]{2,7}", "*********@******", "ALL" )
</cfscript>
<cfoutput>ORIGINAL TEXT: <br />#comments#</cfoutput>
<cfoutput>CLEANED TEXT: <br />#cleanContent#</cfoutput>
Sorry about that, I did not look closely enough at my regexp. This one does work though!
Copy link to clipboard
Copied
Thanks for your help! Works great now. Have a great weekend!
Copy link to clipboard
Copied
You are welcome. Sorry for the goof on the initial regexp and you have a great weekend, too!