javascript - Removing blank lines from textarea with jQuery -


first, i've tried possible solutions i've found here or google, no 1 seems work me.

to clear, need remove every empty lines text area. i've done far:

<textarea name="text" class="form-control" rows="14" id="text" placeholder="here goes our query" ></textarea>   $(document).ready(function () {     $('#text').focusout(function () {         var text = $('#text').val();          text.replace(/(\r\n|\n|\r)/gm,"");          alert('done');     }); }); 

i successful alert on end, empty lines still there. regexp correct ? knowledge js not big, need :(

http://www.w3schools.com/jsref/jsref_replace.asp

the replace() method searches string specified value, or regular expression, , returns new string specified values replaced.

so not changing textarea value.

you can use

$(document).ready(function () {     $('#text').focusout(function () {         var text = $('#text').val();         text = text.replace(/(?:(?:\r\n|\r|\n)\s*){2}/gm, "");         $(this).val(text);     }); }); 

the regex here.


Comments