JSFiddle - React, Tailwind, and code Playground

by mgibsonbr

HTML

<h1>Erros:</h1>
<div id="erros"></div>

JavaScript

function IsNumeric(str) {
    return !!str.match(/^-?\d*\.?\d+$/);
}

function testar(expressao, esperado) {
    if ( eval(expressao) !== esperado )
        $("#erros").append('<p>' + expressao + '</p>');
}

testar("IsNumeric('-1')",     true);
testar("IsNumeric('-1.5')",   true);
testar("IsNumeric('0')",      true);
testar("IsNumeric('0.42')",   true);
testar("IsNumeric('.42')",    true);
testar("IsNumeric('99,999')", false);
testar("IsNumeric('0x89f')",  false);
testar("IsNumeric('#abcdef')",false);
testar("IsNumeric('1.2.3')",  false);
testar("IsNumeric('')",       false);
testar("IsNumeric('blah')",   false);