title: How can I Accept only letter, number, comma (,) and dot (.) using php
body: <p>I want to accept only letter, number, comma and dot using following regular expression. If i use <code>$string</code>it's saying invalid data but If i use <code>$string2</code> it's saying valid data. </p>
  
  <p>1) Why <code>$string</code> is not accepting as valid data ? anything I'm missing ?   </p>
  
  <p>2) If i accept comma then how can I escape it ? Using mysqli_real_escape_string ? If so then it's showing backslash when I showing it from Db.  Please help. Thank You. </p>
  
  <pre><code>$string = "I m a good boy";
  $string2 = "Imagoodboy";
  
  if(preg_match("/^[a-zA-Z0-9]+$/", $string) == 0)
      echo "Invalid data";
  else
      echo "Valid data";
  </code></pre>