title: JSLint and my Javascript - Best practices on making this script conform
body: <p>A function I put together (which runs but doesn't validate under JSLint) is as follows:</p>
  
  <pre><code>function toNumber(str)
  {
   str = str.toString().replace(/[^0123456789.-]/g,'');
   if (str == "") {return 0;}
   return parseFloat(str);
  }
  </code></pre>
  
  <p>This is intended to take any given string and convert it to a number for use elsewhere in my javascript.  Example runs as follows:</p>
  
  <p>toNumber("5") => 5</p>
  
  <p>toNumber("3,276") => 3276</p>
  
  <p>toNumber("-14b396Z") => -14396</p>
  
  <p>The problem here is when I try to validate it with JSLint I get two errors I cannot resolve.</p>
  
  <pre><code> line 25 character 36  str = str.toString().replace(/[^0123456789.-]/g,'');
    Insecure '^'.
   line 25 character 48  str = str.toString().replace(/[^0123456789.-]/g,'');
    Unescaped '-'.
  </code></pre>
  
  <p>I know I can turn on the "and [^...] in /RegExp/" to ignore the first error, but that still leaves me with the second.  What would be the best way to solve both errors?  I figure if I'm going to rewrite this anyway I might as well do so for both errors instead of just turning a blind eye to the 'Insecure' nature of using ^.</p>
  
  <p>Thank you,
  - Aaron Nichols</p>