JQUERY - Load in form with editor

0

It is possible to play text that is misaligned and full of spaces on the left, above and below. Leave it all aligned and no spaces?

For example:

    
       texto
texto
texto texto
         texto 

and exit like this, all without spaces and left aligned:

texto
texto
texto texto
texto

This is already automatic when pasting into the editor (textarea).

    
asked by anonymous 25.05.2018 / 19:08

1 answer

1

Using jQuery, it looks like this:

$("textarea#txt1").on('input',function(){
  var txt = $(this).val();
  var txt_novo = txt.replace(/(^|[\n\r])([\t\s])+/g, "$1");
  $(this).val(txt_novo);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><textareaid="txt1" style="width:350px; height: 250px;"></textarea>
    
25.05.2018 / 21:07