replacing chars using jQuery
<p>I am trying to replace all special characters except alphanumerics using js.</p>

<pre><code>function checkWholeString(string,len){
        if(string != null &amp;&amp; string != ""){
            var regExp = /^[A-Za-z0-9-]+$/;
            for(var i=0; i &lt; string.length; i++){
                var ap = string.charAt(i);
                if(!ap.match(regExp)){
                   string = string.replace(ap," ");
                }
            }
            return jQuery.trim(string);
        }
    }
</code></pre>

<p>trouble is when I am holding for example "a" key pressed and while I am still holding it I will press another key it will add blank spaces to the text.</p>

<p>Is there any chance to improve the code to get rid of this?
Any help would be most welcome.</p>

<p>Thanks
Pete </p>
