title: Validate Username with regex
body: <p>I am in the process of developing a registration form. It has the following requirements:</p>
  <ul>
  <li>can contain uppercase and capital letters, numbers, and character set</li>
  <li>must not contain spaces</li>
  <li>length from 5 to 16 characters</li>
  </ul>
  <p>I will check the string like this.</p>
  <pre><code>extension String {
  
      var isValidUsername: Bool {
          let predicate = NSPredicate(format: &quot;SELF MATCHES %@ &quot;, &quot;^(?=.*[A-Za-z0-9!@#$%^&amp;*()._-]).{5,16}$&quot;)
  
          return predicate.evaluate(with: self)
      }
  
  }
  </code></pre>
  <p>Now there are 2 problems I can enter the spaces, although I should not. I can use characters other than those listed. How do I fix this?</p>