diff --git a/app/assets/javascripts/frontend/form-validation.js.coffee b/app/assets/javascripts/frontend/form-validation.js.coffee index 0a2bcc8a6..bb0fc41ed 100644 --- a/app/assets/javascripts/frontend/form-validation.js.coffee +++ b/app/assets/javascripts/frontend/form-validation.js.coffee @@ -140,7 +140,8 @@ window.FormValidation = validateWordLimit: (question) -> textarea = question.find("textarea") wordLimit = textarea.attr("data-word-max") - normalizedContent = textarea.val().replace(/ /g, ' ').replace(/\n/g, ' '); + textareaValue = textarea.val() || ''; + normalizedContent = textareaValue.replace(/ /g, ' ').replace(/\n/g, ' ').replace(/\s+/g, ' ').trim(); wordCount = normalizedContent.split(" ").length if wordCount > wordLimit @logThis(question, "validateWordLimit", "Word limit exceeded")