This is to check only digits in a string.. It’s returning true when I expected to return me a false..
How can I fix this and why it’s returning me a true?
<script type="text/javascript">
function test()
var str2 ="s123s";
var reg3 =/\d/;
alert(reg3.test(str2));
}
</script>
You regex is testing if there is one digit in the string — and not if the string contains only digits.
If you what to check for a string that
you should change your regex to something like this :