<p>So I am writing a registration form and I need the display name to be only numbers, letters and underscores. </p>

<p>Have a look at my code and tell me what I'm doing wrong.</p>

<pre><code>&lt;form method="post" action="/" onsubmit="return check_form()"&gt;
    &lt;input type="text" id="display-name" name="display-name" maxlength="255" /&gt;
    &lt;input type="submit" /&gt;
&lt;/form&gt;
&lt;script type="text/javascript"&gt;
&lt;!--
    var name_regex = /^([a-zA-Z0-9_])+/

    function check_form()
    {
        if (!name_regex.test(document.forms[0].elements[0].value))
        {
            document.forms[0].elements[0].focus()
            alert("Your display name may only contain letters, numbers and underscores")
            return false
        }
    }
--&gt;
&lt;/script&gt;
</code></pre>

<p>It's obviously been trimmed down to not include anything not related to the problem but even this snippet doesn't work.</p>

My regexp would go along the lines of:
```
/^[a-zA-Z0-9_]+$/
```
edit: I think it's the lack of a line end
```
$
```
that makes it fail.