Strip clean input value

Remove any non printable characters from input string

HTML

<textarea>​[email protected]</textarea><br>
<button>Remove</button>
<div id="status"></div>

CSS

textarea {
    width: 300px;
    height: 50px;
    outline: none;
    font-family: Monaco, Consolas, monospace;
    border: 0;
    padding: 15px;
    color: hsl(0, 0%, 27%);
    background-color: #F6F6F6;
}

JavaScript

$('button').click(function() {
    var bp = $('textarea').val();
    
    var h = '<br>BEFORE CONV string length:' + bp.length + '<br><br>';
    
    var ap = bp.replace(/[^\u0020-\u007E]/g, '');
    $('textarea').val(ap);
    $('textarea').focus()[0].select();
    
    // Convert each character to hex value
    for(var i = 0; i < bp.length; i++) {
        h += i + ': [' + bp[i] + ']' + bp.charCodeAt(i).toString(16) + '<br/>';
    }
    
    h += '<br>AFTER CONV string length:' + ap.length + '<br><br>';
    
    $('#status').html(h);
});