This is the initial text in Text Area
After clicking on format button.
<html>
<head>
<script type="text/javascript">
function formattext(id)
{
var input = document.getElementById(id).value; // get textarea contents
console.log("The First Time user enters data : " + input)
input = input.replace(/ +/g, " "); //Removes Space from textarea contents
console.log("When spaces are removed : " + input)
input = input.replace(new RegExp('\r?\n', 'g'), '<br />'); //Removes new line
console.log("When new line is removed : " + input);
input = input.replace(/<br\s*\/?>/g, ''); //Removes br
console.log("When br is removed : " + input)
document.getElementById(id).value = input;
}
</script>
</head>
<body>
<textarea id="txtareaProjectDes" rows="4" cols="50">
</textarea>
<button onclick="formattext('txtareaProjectDes')">Format Text</button>
</body>
</html>