Cyberomin
Cyberomin

Reputation: 523

jQuery rich text editor with word counter

I need a rich text editor like this one used on this site, with a word counter on it, i will love to restrict the total work count like on twitter, preferrably written with jQuery, please any tip, i will greatly appreciate it.

Upvotes: 2

Views: 1618

Answers (2)

Simon Lang
Simon Lang

Reputation: 42675

I would recommend TinyMCE for all your rich text editing needs. I haven't looked, but I bet there is a word count plugin for it.

Upvotes: 3

Marcelo Cantos
Marcelo Cantos

Reputation: 185862

The editor on SO isn't "rich" in any real sense of the word. It's just a <textarea>. To do word-count limiting, simply access the relevant DOM field (text or value, I suppose; not my area of expertise, sorry), split on spaces, and refuse to submit if the resulting array is too long.

You will have to be careful with people trying to game the rules by, e.g., writing entire paragraphs with underscores instead of spaces. You could split on any non-word characters instead (which they might game by just mashing words together), or limit the number of characters as well as the number of words. By far the simplest option, however, is to just limit the character count like SO does.

Upvotes: 0

Related Questions