title: How to use preg_match to not allow space in the front and in the end, but allow in between
body: <p>I have looked around, and I found a lot of tutorials out there. But none of them could help in my case.
  Here is my script:</p>
  
  <pre><code>if(!preg_match('/^[0-9A-Za-z!@#$%]+$/',$user_name)) {
    echo"bad username";
  } 
  </code></pre>
  
  <p>This code not allow any spaces no matter what if they´re in the front, the end or in between.</p>
  
  <p>I want to allow just between but not in the front and in the end.</p>
  
  <p>Anyone can help me please ?</p>