Skip Navigation

[Resolved] Limit Number of Allowed Words (Not Characters) in a Form Field

This support ticket is created 4 years, 2 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 2 replies, has 2 voices.

Last updated by Ed 4 years, 2 months ago.

Assisted by: Nigel.

Author
Posts
#1749475

Ed

I'm building a website for a classified ads company. I need to limit the number of WORDS (not characters) in a text field or text area. Is there a way to do this?

#1753645

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Ed

There isn't any such option within Toolset. In the forums you'll see people have worked on their own solutions to this over the years, though typically when limiting the field length by characters.

It's straightforward enough to count the words instead (by counting spaces), see this as an example: hidden link.

You'd need to write some jQuery/JavaScript which attaches an event listener for changes to the input field, counts the number of words, and disables the input once it reaches the limit.

I didn't come across a solution that matches your requirement for words, and as this is custom code you'll need to come up with the solution, but you should be able to find some examples to get you started in the forum.

#1753745

Ed

My issue is resolved now. Thank you!