Expand my Community achievements bar.

Learn about Edge Delivery Services in upcoming GEM session
SOLVED

Limit word count in a text field?

Avatar

Level 2

I have two fields:

txtStageContent (where the user types in information)

WordCountResult (this field displays the words counted in the txtStageContent)

in the exit event for txtStageContent I have the following code to count the number of words (which works):

var cnt = word_count(this.rawValue);

WordCountResultTwo.rawValue = cnt.toString();

function word_count(textParam)

{

          textParam = textParam.replace(/^\s*|\s*$/g,'');

            if (textParam)

                      return textParam.split(/\s+/).length;

          else

                      return 0;

}

My Question is:

I would like to have a limit of 700 words in the txtStageContent text field, can this be done?

Thanks in advance for your help!!

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi,

this can be done with a small script in the the change event.

if (xfa.event.newText.match(/\b\w+?\b/g).length > 700) {

          xfa.event.change = "";

}

View solution in original post

2 Replies

Avatar

Correct answer by
Level 10

Hi,

this can be done with a small script in the the change event.

if (xfa.event.newText.match(/\b\w+?\b/g).length > 700) {

          xfa.event.change = "";

}

Avatar

Level 2

Perfect!! This is just what I needed. Thank you very much for your help!