Skip to content Skip to sidebar Skip to footer

Can't Remove Empty Line Break In Textarea With Javascript Replace Method

When I paste the following into the text area, when onblur it's supposed to tidy up the text pasted removing certain words, tab spaces and tidying up by placing each value separate

Solution 1:

value=value.replace(/^(\r\n)|(\n)/,'');

Seems to do the trick.

DEMO

Also, you can emulate tab characters in html with 	, not to mention that you don't need to prefix javascript in events with javascript:.

Solution 2:

Or just add \t after the first replace:

value=value.replace(/(Customer account\t|Name\t|Street name\t|Telephone\t|City\t|postcode\t|Extension\t)/g,'');

The problem arises, because you have a tab after the last title.

Solution 3:

A regex would work like so, if you were to go that way:

str.replace(/^$/m, '');  

Yes? Someone sanity check this for me?

Post a Comment for "Can't Remove Empty Line Break In Textarea With Javascript Replace Method"