title: convert regex string to regex object in javascript
body: <p>I am getting <code>regex</code> string from json object (yes its dynamic and will be always be string) i want to test this with textbox value.</p>
  
  <p>But even if i pass valid input text it does not pass <code>regex</code> condition</p>
  
  <p>code :</p>
  
  <pre><code>var pattern = "/^[A-Za-z\s]+$/";
  var str = "Some Name";
  pattern = new RegExp(pattern);
  if(pattern.test(str))
  {
      alert('valid');
  }
  else
  {
      alert('invalid');
  }
  </code></pre>
  
  <p>Fiddle :- <a href="http://jsfiddle.net/wn9scv3m/" rel="noreferrer">http://jsfiddle.net/wn9scv3m/</a></p>