Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

Limit word count in a text field?

ahlaj77
Level 2
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
radzmar
Correct answer by
Level 10
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
radzmar
Correct answer by
Level 10
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

ahlaj77
Level 2
Level 2

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