How to make this code more useful (preventing special characters in textarea)
<p>i am using this code and working fine but the problem with this code is, its not optimized and for an example if i want to add few more characters then i will end-up having ifs.... </p>

<pre><code>if (keychar == "#" || keychar == "!" || keychar == "$" ..........)
</code></pre>

<p>is there a way to optimized this code? meaning less ifs (if i need to add more special characters to prevent)</p>

<pre><code> &lt;script language="javascript" type="text/javascript"&gt;
        function check(e) {
            var keynum
            var keychar
            var numcheck
            // For Internet Explorer
            if (window.event) {
                keynum = e.keyCode
            }
            // For Netscape/Firefox/Opera
            else if (e.which) {
                keynum = e.which
            }
            keychar = String.fromCharCode(keynum)
            //List of special characters you want to restrict
            if (keychar == "'" || keychar == "a") {

                return false;
            }
            else {
                return true;
            }
        }
&lt;/script&gt;
</code></pre>
