This code is so sweet it will rot your teeth out and it hurts to give it out but here ya go:

1. Put this at the top of the page. it will parse the FORM scope b4 it goes into any local variable or db. It checks for any code that is outside the ASCii 255 character set.

2. You can easily modify it to accept whatever scope ya wanna loop thru and you can change what it replaces the unrecognized char with. It defaults to a blank space.

Without further todo:

<cfif isDefined("form")>
    <cfloop collection ="#form#" item="letter">
        <cfset tcurrentFormValue
= form[letter]>
        <cfloop from=
"1" to="#Len(tcurrentFormValue)#" index="x">
            <cfset currentPos=Mid
(tcurrentFormValue,x,1)>
            <cfset ascVal=asc
(currentPos)>
            <cfif ascVal
GT 255>
                <cfset tcurrentFormValue=ReplaceNoCase
(tcurrentFormValue,currentPos," ","ALL")>
            </cfif>
        </cfloop>
    </cfloop>
</cfif>


if they cut and paste from Word or Works it will grab the junk!!!!!!

About This Tutorial
Author: Michael "Newkirk" MacDonald
Skill Level: Intermediate 
 
 
 
Platforms Tested: CFMX
Total Views: 32,592
Submission Date: March 12, 2005
Last Update Date: June 05, 2009
All Tutorials By This Autor: 5
Discuss This Tutorial
  • Please do not forget Unicode chars which are bigger than 255. :)

  • Does this code will work also with paste from word as html? I been having big problem with same web tempalte that I create for teacher and after I upted the coldfusion server from 5 to 6.1 when they paste as html and after we review comas and " or - are replaced by boxex

  • I've been under the weather lately and taking every Med possible so please forgive my last post titled "Tutorial fix,Please READ" The vaule of "x" is already declared and it is incremented by the inner loop...DOHHHH!!!! Sorry for wasting your time with the panic stricken, drug induced tutorial add-on. If you have any problems with this code please post it here along with the special chars you are using and we can see why its not working. I have used this code with bad chars with ascii values up to 60000 with no problems.

  • The x in the mid function needs o be defined and incremented so you loop thru the whole string here is the whole function again including what was left out when i cut and pasted...

Advertisement

Sponsored By...
Powered By...