how to pass a variable into an regular expression in javascript
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/494035/how-do-you-pass-a-variable-to-a-regular-expression-javascript">How do you pass a variable to a Regular Expression JavaScript?</a>  </p>
</blockquote>



<p>I need help to resolve the issue because the code fails due to 
numLength[0]:</p>

<pre><code>&lt;html&gt;
&lt;body&gt;

&lt;script type="text/javascript"&gt;
function xyz(){
var predefLength = "5,5";
var number = "20";
var numLength = predefLength.split(",");
var result = /^[-+]?\d{0,numLength[0]}(\.\d{0,numLength[1]})?$/.test(number);
document.write(result);
}
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Any help will appreciated.</p>
