title: Jquery - Convert string to reg exp object
body: <p>My regular expression is <code>/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/</code> and in html I added it as a hidden element with the value of the element set to the above pattern</p>
  
  <p>When I do this:</p>
  
  <pre class="lang-js prettyprint-override"><code>var regex = /^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/ 
  var text = $(this).val()
  </code></pre>
  
  <p>and then test with <code>regex.test(text)</code> it works fine.</p>
  
  <p>but when I assign regex like this:</p>
  
  <pre><code>var regex = $("#m"+id).val() // (my hidden element)
  </code></pre>
  
  <p>then it doesnt work. I have tried assigning it using new RegExp as well but also not working.I think it's doing it because it's returning the value as a string from <code>$("#m"+id).val()</code> (I am getting the right value returned here), but not sure what to parse it to.</p>
  
  <p>Any help would be appreciated.</p>