title: PHP verify valid UUID
body: <p>I found the following Javascript function in <a href="https://stackoverflow.com/a/873856/367456">another answer</a>:</p>
  
  <pre><code>function createUUID() {
      var s = [];
      var hexDigits = "0123456789abcdef";
  
      for (var i = 0; i &lt; 36; i++) {
          s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
      }
  
      s[14] = "4";
      s[19] = hexDigits.substr((s[19] &amp; 0x3) | 0x8, 1);
      s[8] = s[13] = s[18] = s[23] = "-";
  
      var uuid = s.join("");
      return uuid;
  }
  </code></pre>
  
  <p>This creates an RFC valid UUID/GUID in javascript.. What I want to know is if there is a way to validate the string once it arrives to the PHP side. I found a regex that would potentially validate everything roughly that format as true:</p>
  
  <p><code>/^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/</code></p>
  
  <p>but using that as long as you specified a string of equal length and format it would pass validation.</p>
  
  <p>Is there any way to add some sort of seed to the javascript function and then verify that in the PHP or if there was a way for PHP to validate the number that was passed matches with the correct format or something?</p>
  
  <p>Any help is greatly appreciated.</p>