 <p>You could search for any characters <strong>not</strong> in the list (a "negated <a href="https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/RegExp#character-sets" rel="nofollow">character set</a>"):</p> <pre><code>var badUsername = /[^a-zA-Z0-9_]/; console.log(!badUsername.test("HELO $")); </code></pre> <p>or more simply</p> <pre><code>var badUsername = /\W/; </code></pre> <p>since <code>\W</code> is defined as</p> <blockquote> <p>Matches any character that is not a word character from the basic Latin alphabet. Equivalent to <code>[^A-Za-z0-9_]</code>.</p> </blockquote> <p>If you prefer to do a positive match, using anchors as other answers have suggested, you can shorten your regexp by using <code>\w</code>:</p> <pre><code>var goodUsername = /^\w+$/; </code></pre>