Reputation: 265
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
Reputation: 14025
Use javascript regex
$('#myTextArea').val($('#myTextArea').val().replace(/ +(?= )/g, '').replace(/\n+/g, ''));
http://jsfiddle.net/UQTY2/241/
Upvotes: 2
Reputation: 1753
Suppose your textarea name is textarea
then use
$('#textarea').val().replace(/ /g, '').replace(/\n/g, '');
This should work out.
Upvotes: 0