Remove lines when pasting?

This would prevent new line on textarea when pressing enter key:

$(‘#text_description’).keypress(function(e) {
if(e.keyCode == 13) { e.preventDefault() }
});

but how to remove lines when pasting into text area?

The easiest way is to take the entire contents of the textarea, remove the newlines using a regular expression, and replace the contents with the new string. The difficulty is listening for the “pasting” event, which is especially difficult when the user has dragged text in or used the mouse’s context menu. There is a newish “onpaste” event, but it is unsupported across browsers. So you can use “onpaste” but you will also have to use onkeyup (for ctrl+v) and onchange (for context menu paste).