title: PHP: check for invalid characters (all but a-z, A-Z, 0-9, _, -, ., @)?
body: <p>I would like to check if a string contains only these characters :</p>
  
  <pre><code>A-Z
  a-z
  0-9
  -
  @
  _
  .
  </code></pre>
  
  <p>The purpose is to check if a mail is valid in a form.</p>
  
  <p>I am doing this :</p>
  
  <pre><code>if(preg_match('/[a-z0-9\._\-\@]/i', $email) === 0) {
          echo 'not valid';
      }
  
  if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      echo 'not valid';
  } 
  </code></pre>
  
  <p>but is doesn’t return an error if there is a special character like </p>
  
  <blockquote>
    <p>test%@test.fr</p>
  </blockquote>