1
I need to validate a string
using Expressão Regular
, it can only contain numbers. So I tried using the following expression /[0-9]/
, but if the string
contain a character and a number is considered valid.
er = new RegExp(/[0-9]/);
document.getElementById("retorno").innerHTML = "" +
"s = " + Boolean(er.exec("s")) + "<br>" +
"s10 = " + Boolean(er.exec("s10")) + "<br>" +
"10 = " + Boolean(er.exec("10")) + "<br>" +
"10,0 = " + Boolean(er.exec("10,0")) + "<br>";
<div id="retorno"></div>
NOTE: I have also tested using the expression /\d/
and the result was the same.
Thanks, it worked.
– Roberto de Campos