Ad
  • Custom User Avatar

    When there is no match in a string, the match function returns null.
    Since null doesn't have the length property, your code throws the error when the string has no non-whitespace characters. Note that your check only works for empty strings, not for strings which constitute entirely of spaces.