title: How to allow underscore and dash with ctype_alnum()?
body: <p>How can I add the exception of <code>_</code> and <code>-</code> as valid characters when using <a href="http://php.net/manual/en/function.ctype-alnum.php" rel="nofollow noreferrer">ctype_alnum()</a> ?</p>
  <h3>I have the following code:</h3>
  <pre><code>if ( ctype_alnum ($username) ) {
  
    return TRUE;
  
  } elseif (!ctype_alnum  ($username)) {
      
    $this-&gt;form_validation-&gt;set_message(
      '_check_username',
      'Invalid username! Alphanumerics only.'
    );
  
    return FALSE;
  }
  </code></pre>