title: Finding an exact match in a text file using PHP AJAX jQuery form
body: <p>I have a .txt file where I would like to find an EXACT match of a single email entered in a form.</p>
  
  <p>The present directives (see below) I used, work for a standard form. But when I use it in conjunction with an AJAX call and jQuery, it confirms it exists by just finding the first occurrence.</p>
  
  <p>For example:</p>
  
  <p>If that person enters "bobby@" it says not found, good.</p>
  
  <p>If someone enters their full Email address and it exists in the file, it says "found", very good.</p>
  
  <p>Now, if someone enters just "bobby", it says "found", not good. </p>
  
  <p>I used the following three examples below with the same results.</p>
  
  <pre><code>if ( !preg_match("/\b{$email}\b/i", $emails )) {
  
  echo "Sorry, not found";
  
  }
  </code></pre>
  
  <p>and...</p>
  
  <pre><code>if ( !preg_match( "/(?:^|\W){$email}(?:\W|$)/", $emails )) {
  
  echo "Sorry, not found";
  
  }
  </code></pre>
  
  <p>and...</p>
  
  <pre><code>if ( !preg_match('/^'.$email.'$/', $emails )) {
  
  echo "Sorry, not found";
  
  }
  </code></pre>
  
  <p>my AJAX</p>
  
  <pre><code>$.ajax({  
  type: "POST",  
  url: "email_if_exist.php",  
  data: "email="+ usr,
  success: function(msg){
  </code></pre>
  
  <p>my text file</p>
  
  <pre><code>Bobby Brown bobby@somewhere.com
  Guy Slim guy@somewhere.com
  Slim Jim slim@somewhere.com
  </code></pre>
  
  <p>I thought of using a jQuery function to only accept a full email address, but with no success partly because I didn't know where to put it in the script.</p>
  
  <p>I've spent a lot of time in searching for a solution to this and I am now asking for some help.</p>
  
  <p>Cheers.</p>