Sauter la navigation

[Résolu] Limit Number of Allowed Words (Not Characters) in a Form Field

This support ticket is created Il y a 4 années et 9 mois. 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+01:00)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par Ed Il y a 4 années et 9 mois.

Assisté par: Nigel.

Auteur
Publications
#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

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+01: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: lien caché.

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!