<p>What's the cleanest, most effective way to validate decimal numbers in JavaScript?</p>

<p>Bonus points for:</p>

<ol>
<li>Clarity. Solution should be clean and simple.</li>
<li>Cross-platform.</li>
</ol>

<p>Test cases:</p>

<pre><code>01. IsNumeric('-1')      =&gt; true
02. IsNumeric('-1.5')    =&gt; true
03. IsNumeric('0')       =&gt; true
04. IsNumeric('0.42')    =&gt; true
05. IsNumeric('.42')     =&gt; true
06. IsNumeric('99,999')  =&gt; false
07. IsNumeric('0x89f')   =&gt; false
08. IsNumeric('#abcdef') =&gt; false
09. IsNumeric('1.2.3')   =&gt; false
10. IsNumeric('')        =&gt; false
11. IsNumeric('blah')    =&gt; false
</code></pre>

This way seems to work well:
```
```
function IsNumeric(input){
    var RE = /^-{0,1}\d*\.{0,1}\d+$/;
    return (RE.test(input));
}
```
```
In one line:
```
```
const IsNumeric = (num) => /^-{0,1}\d*\.{0,1}\d+$/.test(num);
```
```
And to test it:
```
```
const IsNumeric = (num) => /^-{0,1}\d*\.{0,1}\d+$/.test(num);
    
    function TestIsNumeric(){
        var results = ''
        results += (IsNumeric('-1')?"Pass":"Fail") + ": IsNumeric('-1') => true\n";
        results += (IsNumeric('-1.5')?"Pass":"Fail") + ": IsNumeric('-1.5') => true\n";
        results += (IsNumeric('0')?"Pass":"Fail") + ": IsNumeric('0') => true\n";
        results += (IsNumeric('0.42')?"Pass":"Fail") + ": IsNumeric('0.42') => true\n";
        results += (IsNumeric('.42')?"Pass":"Fail") + ": IsNumeric('.42') => true\n";
        results += (!IsNumeric('99,999')?"Pass":"Fail") + ": IsNumeric('99,999') => false\n";
        results += (!IsNumeric('0x89f')?"Pass":"Fail") + ": IsNumeric('0x89f') => false\n";
        results += (!IsNumeric('#abcdef')?"Pass":"Fail") + ": IsNumeric('#abcdef') => false\n";
        results += (!IsNumeric('1.2.3')?"Pass":"Fail") + ": IsNumeric('1.2.3') => false\n";
        results += (!IsNumeric('')?"Pass":"Fail") + ": IsNumeric('') => false\n";
        results += (!IsNumeric('blah')?"Pass":"Fail") + ": IsNumeric('blah') => false\n";
        
        return results;
    }

console.log(TestIsNumeric());
```
```
```
```
.as-console-wrapper { max-height: 100% !important; top: 0; }
```
```
I borrowed that regex from
http://www.codetoad.com/javascript/isnumeric.asp
. Explanation:
```
```
/^ match beginning of string
-{0,1} optional negative sign
\d* optional digits
\.{0,1} optional decimal point
\d+ at least one digit
$/ match end of string
```
```