title: Regular expression for password with certain special characters excluding all others
body: <p>I have to provide a data annotation regex for a password that's specified as:</p>
  
  <pre><code>min 8 chars
  min 1 upper
  min 1 lower
  min 1 numeric
  min 1 special char which can ONLY be one of the following:$|~=[]'_-+@. (and the password can contain no other special chars besides these)
  </code></pre>
  
  <p>It's the exclusion of special characters which is giving me the headache.</p>
  
  <p>I've come up with this but it just does not work:</p>
  
  <pre><code>"^.*(?=.{8,})(?=.*[a-z])(?=.*[A-Z])(?=.*[\d])**(?(?!.*[^$|~=[\]'_\-+@.])|([^\W\w])).*$**
  </code></pre>
  
  <p>It resolves everything I enter as invalid.</p>
  
  <p>Whereas this (for the special chars) on its own does work:</p>
  
  <pre><code>"(?(?!.*[^$|~=[\]'_\-+@.])|([^\W\w])).*$"
  </code></pre>
  
  <p>and I know the first part works, so what am I missing to make them work together?</p>
  
  <p>Alternatively, is there a much simpler way of achieving this?</p>
  
  <p>(.NET environment)</p>