0

I am trying to detect spaces on textarea my code is following

textarea.value.replace(/\s/g, ' ');

but it detects all whitespaces and I want to detect only spaces...

is any solution??

2
  • 2
    Use / /g maybe? Should work. Commented Jul 25, 2013 at 21:07
  • 2
    If you don't want to use whitespace literally in a regex you can also use /\u0020/g Commented Jul 25, 2013 at 21:20

3 Answers 3

6
textarea.value.replace(/ /g, ' ');
// that's a space ------^
Sign up to request clarification or add additional context in comments.

3 Comments

+1 for ascii-art arrows.
@maxART Instead of thanking him in a comment, accept his answer. :)
I can not now :) I will after 6 minute :)
3

use a literal space, like so:

textarea.value.replace(/ /g, ' ');

Comments

0

Use this:

textarea.value.replace(/[ ]/g, ' ');

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.