Javascript trying to count multiple spaces as one — in the textarea, but does not work. Why?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
10 views
Hello. Why script is not working as I expect? Try to write a single character, then a lot of spaces and another character. Blanks will be counted ALL. And I need it to count only one.
https://jsfiddle.net/49pemc0x/
by | 10 views

2 Answers

0 like 0 dislike
Wrong regular expression define - quotation marks are not needed. And easier. it can be done, somehow so.
by
0 like 0 dislike
Yes, the quotes are not needed!
And a bunch of extra code )) That this is enough :
$('#text').on('input', function() { var string = $(this).val(); string = string.replace(/\\s+/g, ' ').trim(); $('#output').text(string.length); }); why two times to process a string?
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked May 23, 2019 by andrey_levushkin
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
110,608 questions
257,187 answers
0 comments
40,796 users