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??

4

3 回答 3

6
textarea.value.replace(/ /g, ' ');
// that's a space ------^
于 2013-07-25T21:08:37.157 回答
3

使用文字空间,如下所示:

textarea.value.replace(/ /g, ' ');
于 2013-07-25T21:07:49.473 回答
0

用这个:

textarea.value.replace(/[ ]/g, ' ');
于 2013-07-25T21:07:51.427 回答