Using word validation limit of 500, I pasted in 500 words into WYSIWYG editor, TinyMCE, and it's word count was 500. On save the field validator kicked in with a warning. I had to reduce this to about 488 before it passed the 500 word limit.

Here's an example code that we have used in the past to do similar validation, not the most efficient but it works and may help.

  $value = $form_state['values']['body'];
  $count = count(explode(' ', trim(preg_replace('/\s+/', ' ', str_replace('&nbsp;', ' ', (strip_tags(str_replace('<', ' <', $value))))))));
  if ($count > 60) {
    form_set_error('body', t('Description must be less than 60 words. Current length is '. $count), $form_state);
  }

Comments

g089h515r806’s picture

I just copy the logic from webform validation. we need more preprocess before validation.

g089h515r806’s picture

Status: Active » Fixed

I have copy your logic code into the latest dev version.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.