• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Remove unwanted characters before entering database?

Participant ,
Jan 27, 2010 Jan 27, 2010

Copy link to clipboard

Copied

I usually remove udnesirable special characters that could be entered in a form before submitting to a database with this

<cfset variable = #Replace(variable,"%","", "all")#>

is there a better way I could simply list all of the unwanted values and just replace from that list?

TOPICS
Advanced techniques

Views

502

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 28, 2010 Jan 28, 2010

Copy link to clipboard

Copied

The safetext function at cflib.org might help you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 15, 2010 Feb 15, 2010

Copy link to clipboard

Copied

I use something like this (below) to not only replace characters, but entire words from strings.   I use mostly use this code to replace 'bad words' in moderated forums with 'alternative text'.

Assume you have a field called 'newdata' for your user to fill out, and they type the following:

"In 99% of the studies, someone always badwords ^ the flow of the discussion"

.

Run this against the 'newdata' field before inserting it into the database (or before displaying it on the screen if you want to show it before it is inserted)

<cfset fixeddata = '#ReplaceList(newdata, "%,^,badword"," percent,up,goodword")#'>

The result, if you output the resulting #fixeddata# would read:

"In 99 percent of the studies, somoene always goodwords up the flow of the discussion"

All kinds of possibilities with this.

Hope it helped,

WHeis

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 15, 2010 Feb 15, 2010

Copy link to clipboard

Copied

LATEST

There's replaceList() or reReplace() which could be used here.

--

Adam

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation