Removing unwanted characters from textbox with JQuery
<p>What I would like to get some input on is how to remove certain characters from a textbox (or textarea) with JQuery. I have the code in C# but I can´t seem to translate that to JQuery javascript. My problem is that I don´t know how to get the value from a textbox as a character array which I then can loop through and compare against a given set of unwanted characters.
This is how "far" I have come in JQuery:</p>

<pre><code>$("input[type=text], textarea").change(function() {

   // code here

});
</code></pre>

<p>This is my code in C#:</p>

<pre><code>for (int i = 0; i &lt; charArray.Length; i++)
{
    current = charArray[i];
    if ((current == 0x9) ||

        (current == 0xA) ||

        (current == 0xD) ||

        ((current &gt;= 0x20) &amp;&amp; (current &lt;= 0xD7FF)) ||

        ((current &gt;= 0xE000) &amp;&amp; (current &lt;= 0xFFFD)))
        _validXML.Append(current);
}

return _validXML.ToString().TrimEnd((char)32, (char)160) ;
</code></pre>

<p><strong>UPDATE:</strong></p>

<p>I went with a combination of some answers below (I will upvote them) and my final JQuery looks like this and works:</p>

<pre><code>$(document).ready(function() {
    $(":text, textarea").change(function() {
        var text = "";
        var arr = $(this).val()
        $.each(arr, function(i) {
            var c = arr.charCodeAt(i);
            if ((c == 0x9) ||
                (c == 0xA) ||
                (c == 0xD) ||
                (c &gt;= 0x20 &amp;&amp; c &lt;= 0xD7FF) ||
                (c &gt;= 0xE000 &amp;&amp; c &lt;= 0xFFFD)) 
            {
                text += arr.charAt(i);
            }
        });
        $(this).val(text);
    });
});
</code></pre>

<p>Thanks all!</p>
