title: Validating a GUID in JavaScript
body: <p>I'm trying to build a regular expression that checks to see if a value is an <a href="https://www.rfc-editor.org/rfc/rfc4122" rel="nofollow noreferrer">RFC4122</a> valid GUID. In an attempt to do that, I'm using the following:</p>
  <pre><code>var id = '1e601ec7-fb00-4deb-a8bb-d9da5147d878';
  var pattern = new RegExp('/^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i');
  if (pattern.test(id) === true) {
    console.log('We have a winner!');
  } else {
    console.log('This is not a valid GUID.');
  }
  </code></pre>
  <p>I'm confident that my GUID is a valid GUID. I thought I grabbed the correct regular expression for a GUID. However, no matter what, I always get an error that says its not a GUID.</p>
  <p>What am I doing wrong?</p>