2
I made a script to remove blanks from a string inside a TEXTAREA or INPUT, follow the code just below:
input = 'input[type="text"]:not(.inputData), textarea';
$(document).on('blur', input, function(){
console.log('blur');
$(this).val($(this).val().replace(/\s\s+/g, ' '));
$(this).val($(this).val().replace(/^\s+|\s+$/g, ''));
});
The problem of this code is that it considers the enter that I give inside a textarea as white space as well and it leaves everything in the line Mensa when finished typing, example:
I want you to stay like this:
Testing:
1- Testing
2- Testing
3- Testing
But then the script goes and leaves everything in the same line so considering the between as space also, follows the example:
Testing: 1-Test 2-Test 3-Test
I want you to take out the blanks, but without considering enter as white space, to continue giving this line break normally.
It wouldn’t be easy to figure that out. Thanks ! I’ll give it a read on.
– Lucas Lima