title: Regular Expression in PHP to restrict specified characters
body: <p>I have a regular expression to make and the criteria is like this:
  The string should contain <code>a-z</code> or <code>A-Z</code> or <code>0-9</code> and it may have any of characters like <code>.</code>, <code>-</code>, <code>_</code>. If there are any of these special characters it should happen only once.</p>
  
  <p>what i want is to limit first character to be either a->z or 0-9 and not (. - _) which are allowed after first character and if there is any allowed special characters it should occur only once.</p>
  
  <p>What is the desired formats are like below:</p>
  
  <ul>
  <li>joffinjoy = valid</li>
  <li>joffin.joy = valid</li>
  <li>joffin#joy = <strong>invalid</strong></li>
  <li>joffin.joy_007 = <strong>invalid</strong></li>
  <li>joffin-joy = valid</li>
  <li>joffin-joy_007 = <strong>invalid</strong></li>
  </ul>
  
  <p>This is what i have now.</p>
  
  <pre><code>&lt;?php 
  $buffer = 'joffin.joy';
  if (preg_match('/[^a-z0-9.-_]/i', $buffer)){ 
  echo 'in-valid characters&lt;br/&gt;';
  }else{
  echo 'valid characters&lt;br/&gt;';
  }
  ?&gt;
  </code></pre>