title: Regex (HTML input pattern) for username
body: <p>I don't quite understand how to put a regex expression together. I keep trying to combine stuff from similar threads I've seen here, with stuff I've been googling, but I seem to be doing this all wrong.</p>
  
  <p>The only thing I can get right is</p>
  
  <pre><code>[A-Za-z0-9]{6,20}
  </code></pre>
  
  <p>But when I try to add more to the pattern, it doesn't seem to be working.</p>
  
  <p><strong>NOTE</strong> This is using the <strong>HTML input pattern attribute</strong>.
  I would appreciate some assistance on this, but I would also appreciate if someone could break down the solution for me, so I could comprehend it a little better.</p>
  
  <ul>
  <li>Username can contain uppercase/lowercase letters</li>
  <li>Username can contain numbers</li>
  <li>Username can contain underscore, hyphen or period</li>
  <li>Username cannot contain spaces</li>
  <li>Username cannot contain special characters</li>
  <li>Username should be between 6-20 characters in length</li>
  </ul>
  
  <p>I've tried something like this:</p>
  
  <pre><code>[A-Za-z0-9_-]{6,20}\S
  </code></pre>
  
  <p>I feel like I'm sort of there, but not quite there.</p>