title: Check a String matches a Regex
body: <p>I want to use JavaScript to do some client-side validation to check whether a string matches the regex:</p>
  
  <p>Whath is wrong in my js ..?</p>
  
  <p><a href="http://plnkr.co/edit/IRigIYpE43st5GKsGBRl?p=preview" rel="nofollow">PLUNKER</a></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;body&gt;
  
  &lt;button onclick="myFunction()"&gt;Test&lt;/button&gt;
  
  &lt;p id="demo"&gt;&lt;/p&gt;
  
  &lt;script&gt;
  function myFunction() {
      var str = "30/12/2015";
      var patt = new RegExp("DD/MM/YYYY");
      var res = patt.test(str);
      document.getElementById("demo").innerHTML = res;
  }
  &lt;/script&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>