title: Regex for Validating an Active Directory Object SID
body: <p>I'm looking for a way to validate if an inserted Object SID from Active Directory is valid, is this possible using <code>preg_match()</code> or <code>preg_match_all()</code>?
  I've looked online for a regex for this validation but I couldn't find anything.</p>
  
  <p>Example:</p>
  
  <pre><code>$sid = 'S-1-5-21-1220945662-1202665555-839525555-5555';
  
  if ($validator-&gt;validateSid($sid)) {
      // SID is valid!
  }
  </code></pre>
  
  <p>I'm not skilled in writing regex's, so if anyone has absolutely any input, please let me know, thanks!</p>
  
  <p>EDIT: For anyone looking for the code with the regex below:</p>
  
  <pre><code>preg_match("/^S-1-[0-5]-\d{2}-\d{10}-\d{10}-\d{9}-[1-9]\d{3}/", $search, $matches);
  
  // Returns
  array(
      0 =&gt; S-1-5-21-1220945662-1202665555-839525555-5555
  )
  </code></pre>
  
  <p>Or for a more lenient pattern:</p>
  
  <pre><code>preg_match("/S-1-5-21-\d+-\d+\-\d+\-\d+/", $sid, $matches);
  
  // Returns
  array(
      0 =&gt; S-1-5-21-1220945662-1202665555-839525555-5555
  )
  </code></pre>