Text Modification

Remove tabs, line breaks, etc. from text

by bmarsh123

HTML

<div>
    <input type="button" id="btnTabs" value="Remove Tabs" />
    <input type="button" id="btnLineBreaks" value="Remove Line Breaks" />
</div>
<textarea id="ta"></textarea>

CSS

textarea {
    width: 100%;
    height: 200px;
}
div {
    margin: 5px;
}
input[type=button] {
    margin: 5px;
    padding: 5px 15px;
    background: #ddd;
    border: 0 none;
    cursor: pointer;
    -webkit-border-radius: 5px;
    border-radius: 5px;
}
input[type=button]:hover {
    background: #ccc;
}
input[type=button]:active,
input[type=button]:focus {
    outline: 0;
}

JavaScript

$(function() {
    $('#btnTabs').on('click', function(e) {
        // Remove tabs only
        $('#ta').val($('#ta').val().replace(/\t/g, ''));
        e.stopPropagation();
    });
    
    $('#btnLineBreaks').on('click', function(e) {
        // Remove line breaks only
        $('#ta').val($('#ta').val().replace(/(\r\n|\n|\r)/gm, ''));
    });
});