title: PHP regex pattern modification needed
body: <p>I'm sure this has been asked before and I did read through a lot of posts but nothing helped me.  Since my regex knowledge is limited I thought I would ask for help.</p>
  <p>I need to validate some user input (zip code format).  Only certain characters are allowed:
  <code>A</code>, <code>N</code>, <code>CC</code>, <code>?</code>, space (<code> </code>) and hyphen (<code>-</code>).</p>
  <p><strong>Sample Input Data</strong></p>
  <pre><code>$input = &quot;CC-XNNNNN&quot;, &quot;ANNNNAAA&quot;, &quot;AAAA NAA&quot;, &quot;ANN ????&quot;
  </code></pre>
  <p><strong>Regex Pattern</strong></p>
  <pre><code>$pattern = &quot;(?:C{2})*|A*|N*|\?*|\-*|\ *&quot;
  </code></pre>
  <p><strong>PHP Code</strong></p>
  <pre><code>if(preg_match('/' . $pattern . '/', $input))
  {
   echo(&quot;pass&lt;br&gt;&quot; . PHP_EOL);
  }
  else
  {
   echo(&quot;fail&lt;br&gt;&quot; . PHP_EOL);
  }
  </code></pre>
  <p>I don't think I need to use anchors, because the allowed characters can be in any position.  With the above code I get 'pass' but I should get 'fail' (X not allowed).  I've looked this over so much I can't see the forest for the trees anymore.</p>
  <p>Can anyone see what I've done wrong?  OR is regex the wrong tool for this?</p>