I am trying to remove special characters in my text but preserve line breaks.Though the question has been answered here Preserve line breaks in textarea. However for some reasons its not working in my case which is a textarea. Here is my code
<code> //HTM
<textarea id="inputTextArea" rows="10" cols="50"></textarea>
<button class="clearButton" onclick="removeSpecialCharacters()">Clean Text</button>
<p>Cleaned Text:</p>
<textarea id="outputTextArea" style="white-space: pre-wrap; background: #90d9ab;" rows="10" cols="50" readonly></textarea>
//Javascript Part
let inputText = document.getElementById('inputTextArea').value;
let cleanedText = inputText
.replace(/[^ws]/gi, function(match) {
return match === 'n' ? 'n' : ' ';
})
.replace(/s+/g, ' ') // Replace multiple spaces with a single space
.trim(); // Remove leading and trailing spaces
// Set the cleaned text in the output textarea
document.getElementById('outputTextArea').value = cleanedText;
</code>
<code> //HTM
<textarea id="inputTextArea" rows="10" cols="50"></textarea>
<button class="clearButton" onclick="removeSpecialCharacters()">Clean Text</button>
<p>Cleaned Text:</p>
<textarea id="outputTextArea" style="white-space: pre-wrap; background: #90d9ab;" rows="10" cols="50" readonly></textarea>
//Javascript Part
let inputText = document.getElementById('inputTextArea').value;
let cleanedText = inputText
.replace(/[^ws]/gi, function(match) {
return match === 'n' ? 'n' : ' ';
})
.replace(/s+/g, ' ') // Replace multiple spaces with a single space
.trim(); // Remove leading and trailing spaces
// Set the cleaned text in the output textarea
document.getElementById('outputTextArea').value = cleanedText;
</code>
//HTM
<textarea id="inputTextArea" rows="10" cols="50"></textarea>
<button class="clearButton" onclick="removeSpecialCharacters()">Clean Text</button>
<p>Cleaned Text:</p>
<textarea id="outputTextArea" style="white-space: pre-wrap; background: #90d9ab;" rows="10" cols="50" readonly></textarea>
//Javascript Part
let inputText = document.getElementById('inputTextArea').value;
let cleanedText = inputText
.replace(/[^ws]/gi, function(match) {
return match === 'n' ? 'n' : ' ';
})
.replace(/s+/g, ' ') // Replace multiple spaces with a single space
.trim(); // Remove leading and trailing spaces
// Set the cleaned text in the output textarea
document.getElementById('outputTextArea').value = cleanedText;