Shub
Shub

Reputation: 265

Removing multiple characters (\n and " ") from textarea

I want to remove multiple spaces and \n characters from my textarea using jquery. For example,

"this is    a

dog"

should be "this is a dog"

Please help me out!

Upvotes: 1

Views: 399

Answers (2)

sdespont
sdespont

Reputation: 14025

Use javascript regex

$('#myTextArea').val($('#myTextArea').val().replace(/ +(?= )/g, '').replace(/\n+/g, ''));

http://jsfiddle.net/UQTY2/241/

Upvotes: 2

Suppose your textarea name is textarea then use

$('#textarea').val().replace(/ /g, '').replace(/\n/g, '');

This should work out.

Upvotes: 0

Related Questions