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

Limiting a string to 25 (or x) consecutive characters without a line break, space or tab.

Explorer ,
Dec 06, 2006 Dec 06, 2006

Copy link to clipboard

Copied

We have users who will fill out a textinput with something like "OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO" which blows up our page display. So I want to limit the number of characters they can submit without having some sort of break [\t \r \n \f]. I don't want to modify what they've input, I just want to return a variable to the template which calls the CFModule so that it can inform the users they need to go back and fix it themselves.

What we do now is pass a text string & a numeric value which determines the max.number of characters w/o a break in the text. Right now I'm using a custom tag using Loops and find() statements (see attached code) to accomplish this. It works, but isn't as efficient as I'd like. Some of the strings we'll be checking can be quite long.

I'd like to find a way to search for blocks of characters over 25 (or x) characters long that are not "break" characters such as a space, tab or carriage return. From what I can gather, ReReplace can use length parameters, but I've been unable to get it to do what I want it to do.
Here's my ideal result:
1. I could ReReplace any string over X characters without a break with a junk string (with a scope of one so we don't waste CPU)
2. I would then search the string for any occurance of our new junk string.
3. If the junk string exists, set Caller.ReturnVar to "Invalid"

Does anyone have any thoughts or ideas? Is it possible to do this with the ReReplace tag or should I just stick to what I have? Any suggestions are greatly appreciated!

Thanks,
Rob
TOPICS
Advanced techniques

Views

245

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
Advisor ,
Dec 06, 2006 Dec 06, 2006

Copy link to clipboard

Copied

See the attached.

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 ,
Dec 10, 2006 Dec 10, 2006

Copy link to clipboard

Copied

completely untested, but you could also try something like this:


reFind("^\s{26,#len(input)#}",input)

i don't have the docs in front of me right now, but basically you're saying
"something that's not a string from 26 chars on up to however long your
total string is. i can't remember the notation for "not....", i think it's
the caret but not sure.



"MikerRoo" <webforumsuser@macromedia.com> wrote in message
news:el7kqp$4pj$1@forums.macromedia.com...
> See the attached.
>
>
> <CFSET sRawStrList = 'Supercalifragilisticexpialidocious, '
> & 'Trinitrophenylmethylnitramine, '
> & 'Trinitrophenyl-Methyl-Nitramine, '
> & 'Antidisestablishmentarianism, '
> & 'Deoxyribonucleic Acid, '
> & 'Bob, '
> & '<a
> href="I%20am%20a%20properly%20encoded%20url%20but%20won%27t%20cause%20wrap%20pro
> blems%2Ehtm">Click Me! I dare ya.</a>'
> >
>
> <CFSET iMaxWordLength = 25>
>
> <CFOUTPUT>
> <h3>Should work with all CF MX versions.</h3>
>
> <table>
> <tr>
> <th>String</th>
> <th>Has &quot;word&quot; longer than #iMaxWordLength#
> characters?</th>
> </tr>
> <CFLOOP index="sRawWord" list="#sRawStrList#">
> <tr>
> <td>#sRawWord#</td>
> <td>
> <CFIF REFind ("\S{#iMaxWordLength#}", sRawWord)>
> <!---
> \S MUST be uppercase. --->
> yes
> <CFELSE>
> no
> </CFIF>
> </td>
> </tr>
> </CFLOOP>
> </table>
> </CFOUTPUT>
>


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
Engaged ,
Dec 11, 2006 Dec 11, 2006

Copy link to clipboard

Copied

LATEST
You could implement a spell check widget that would also help to clean up the data input, too.

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