I have used script to remove the double spaces. but this script is removing the new line also along with the space.
Suppose Input is "\s\s\n\n" Script's output is "\s" Desired Output "\s\n\n" That I simply want to remover double space but not new line. Want to skip new line.
function 开发者_JAVA技巧clean(f) {
f.value=f.value.replace(/^\s+|\s+$/g,'').replace(/\s\s+/g,' ');
return true;
}
You're currently using \s
which expunges any whitespace. If you wish to remove double or greater spaces whilst retaining all \n
you can use the following:
replace(/ {2,}/g,'')
精彩评论