Detecting whether user input contains a forbidden character in JavaScript
<p>I have a text box that is going to be validated in JavaScript upon click on the submit button.</p>

<p>Only the character 0-9 and a-f and A-F are allowed.</p>

<p>So g-z and G-Z as well as other characters such as punctuation or not allowed.</p>

<p>The code I have so far is:</p>

<pre><code>function validate_form ( )
{
    valid = true;

    if ( document.form.input.value == [a-zA-Z_,.:\|] )
    {
        alert ( "You can only enter either 0-9 or A-F. Please try again." );
        valid = false;
    }

    return valid;
}
</code></pre>

<p>Which doesn't seem to work.</p>

<p>I'm new to JavaScript so can any one please give me a hint as to where I'm going wrong?</p>
