diff --git a/maxlength.module b/maxlength.module index f117fac..0b0ee2f 100644 --- a/maxlength.module +++ b/maxlength.module @@ -206,7 +206,8 @@ function maxlength_validate_input(&$element, &$form_state) { $value = filter_xss(str_replace(array("\r\n", ' '), array(' ', ' '), $element['#value']), array()); if($element['#maxlength_js_type'] == 'word'){ - $wordArray = preg_split('/\s+/', $value); + $trimmed_value = trim($value); + $wordArray = preg_split('/\s+/', $trimmed_value); $wordCount = count($wordArray); if ($wordCount > $element['#attributes']['maxlength']) { form_error($element, t('!name cannot be longer than %max words but is currently %length words long.', array('!name' => empty($element['#title']) ? $element['#parents'][0] : $element['#title'], '%max' => $element['#attributes']['maxlength'], '%length' => $wordCount)));