title: Editing form to sanitize/validate phone number
body: <p>I have very limited experience with PHP and I'm really hoping someone can help me.</p>
  
  <p>What I want to do is sanitize/validate the phone number input so that only numbers are allowed.</p>
  
  <p>I think I need to use <code>FILTER_SANITIZE_NUMBER_INT</code> but I'm not sure where or how to use it.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;?php
  
  // Replace the email address with the one that should receive the contact form inquiries.
  define('TO_EMAIL', '########');
  
  $aErrors = array();
  $aResults = array();
  
  /* Functions */
  
  function stripslashes_if_required($sContent) {
  
      if(get_magic_quotes_gpc()) {
          return stripslashes($sContent);
      } else {
          return $sContent;
      }
  }
  
  function get_current_url_path() {
  
      $sPageUrl = "http://".$_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
      $count = strlen(basename($sPageUrl));
      $sPagePath = substr($sPageUrl,0, -$count);
      return $sPagePath;
  }
  
  function output($aErrors = array(), $aResults = array()){ // Output JSON
  
      $bFormSent = empty($aErrors) ? true : false;
      $aCombinedData = array(
          'bFormSent' =&gt; $bFormSent,
          'aErrors' =&gt; $aErrors,
          'aResults' =&gt; $aResults
          );
  
      header('Content-type: application/json');
      echo json_encode($aCombinedData);
      exit;
  }
  
  // Check supported version of PHP
  if (version_compare(PHP_VERSION, '5.2.0', '&lt;')) { // PHP 5.2 is required for the safety filters used in this script
  
      $aErrors[] = 'Unsupported PHP version. &lt;br /&gt;&lt;em&gt;Minimum requirement is 5.2.&lt;br /&gt;Your version is '. PHP_VERSION .'.&lt;/em&gt;';
      output($aErrors);
  }
  
  
  if (!empty($_POST)) { // Form posted?
  
      // Get a safe-sanitized version of the posted data
      $sFromEmail = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
      $sFromName = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW);
  
      $sMessage  = "Name: ".stripslashes_if_required($_POST['name']);
      $sMessage .= "\r\nEmail: ".stripslashes_if_required($_POST['email']);
      $sMessage .= "\r\nBusiness: ".stripslashes_if_required($_POST['business']); 
      $sMessage .= "\r\nAddress: ".stripslashes_if_required($_POST['address']);
      $sMessage .= "\r\nPhone: ".stripslashes_if_required($_POST['phone']);
      $sMessage .= "\r\nMessage: ".stripslashes_if_required($_POST['message']);
      $sMessage .= "\r\n--\r\nEmail sent from ". get_current_url_path();
  
      $sHeaders  = "From: '$sFromName' &lt;$sFromEmail&gt;"."\r\n";
      $sHeaders .= "Reply-To: '$sFromName' &lt;$sFromEmail&gt;";
  
      if (filter_var($sFromEmail, FILTER_VALIDATE_EMAIL)) { // Valid email format?
  
          $bMailSent = mail(TO_EMAIL, "New inquiry from $sFromName", $sMessage, $sHeaders);
          if ($bMailSent) {
              $aResults[] = "Message sent, thank you!";
          } else {
              $aErrors[] = "Message not sent, please try again later.";
          }
  
      } else {
          $aErrors[] = 'Invalid email address.';
      }
  } else { // Nothing posted
      $aErrors[] = 'Empty data submited.';
  }
  
  
  output($aErrors, $aResults);
  </code></pre>