title: PHP Validation on a text area using preg_match for numbers, letters, and white space
body: <p>So i have got this almost completely working. The one thing i am stuck on is where to start in <strong>preg_match.</strong> I have read the manual here <a href="http://php.net/manual/en/function.preg-match.php" rel="nofollow noreferrer">http://php.net/manual/en/function.preg-match.php</a> but it doesn't exactly describe to me the syntax for creating my own validation. <strong>Example: for a text area, if i wanna only allow white space, letters, numbers and maybe some special characters(unlikely)</strong>. Here is the code</p>
  
  <pre><code>&lt;?php
      if(isset($_POST['name'])
              &amp;&amp; isset($_POST['phone'])
              &amp;&amp; isset($_POST['email'])) {
  
              if (empty($_POST["name"])) {
                      $nameErr = "Name is required";
              }
              else {
                      $name = $_POST["name"];
                // check if name only contains letters and whitespace for name
                      if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
                              $nameErr = "Only letters and white space 
                                  allowed";
                      }
              }
  
              if (empty($_POST["phone"])) {
                      $phoneErr = "Phone number is required";
              }
              else {
                      $phone = $_POST["phone"];
                       // check if phone only contains numbers for phone
                      if (!preg_match('/^\(?[\d]{3}\)?\s?\-?[\d]{3}\s?\-?[\d]
                          {4}$/', $phone)) {
                              $phoneErr = "Only numbers allowed";
                      }
              }
  
  
              if (empty($_POST["email"])) {
                      $emailErr = "Email is required";
              }
              else {
                      $email = $_POST["email"];
                      // check if e-mail address is well-formed
                      if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                              $emailErr = "Invalid email format";
                      }
              }
  
  
              if($nameErr or $emailErr or $phoneErr){
                      echo $nameErr;
                      echo $phoneErr;
                      echo $emailErr;
                      die();
              }
              else if($data = $_POST['name'] . "\n" .
                      $_POST['email'] . "\n" .
                      $_POST['phone'] . "\n" .
                      $_POST['county'] . "\n" .
                      $_POST['floor'] . "\n" .
                      $_POST['descr'] . "\n"){
  
                      echo "Thank you for your inquery!" . "&lt;br/&gt;" .
                              "An estimator will be with you shortly.";
  
                      mail('theshadowcallsu@gmail.com', 'Estimation Request', 
                            $data);
              }
      }
  
   ?&gt;
  </code></pre>