I need to validate a string
using Expressão Regular
, it can only contain numbers. So I tried to use the following expression /[0-9]/
, but if the string
contains 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 also tried using the expression /\d/
and the result was the same.