title: making special characters optional in regular expression
body: <p>I have following requirement:</p>
  
  <p>password must be 6-18 characters and contain at least one letter and one number. Special characters such as @, %, &amp;, # are permitted.</p>
  
  <p>I have created this:</p>
  
  <pre><code>^.*(?=.{6,18})(?=.*\d)(?=.*[A-Za-z])(?=.*[@%&amp;#]).*$
  </code></pre>
  
  <p>but It accepts other special characters like _ as well and It requires that one of these special characters @%&amp;# must be in string. I want to make this optional. Means if user enters one of these special characters then string should be valid but If user doesn't enter these characters then it should not be invalid. and If user enters any other special character, string should be invalid.</p>