How do I get the amount of numbers in a string? : <p>I currently have a text input in my HTML document and some buttons below it. When pressed, these will run a function <strong>input(some number)</strong>. I have added a feature to the function that prevents the length of the string for the input from being above 5. However, sometimes the string (<strong>currentAnswer</strong>) will be set to something like <em>-768.</em>. When this happens, the function will not let you enter any more numbers, when instead you should be able to enter 2 more digits. So how would I find the length of just the <strong>numbers</strong> in a string? Here is my code:</p>

<pre><code>function input(num) {
currentAnswer = document.getElementById("answerBox").value;
answerLength = currentAnswer.length;

if (answerLength &lt; 5) {

document.getElementById("answerBox").value = currentAnswer + num;
answerLength = answerLength + 1;

}}
</code></pre>

<p>As you can see, I am using <strong>currentAnswer.length</strong> to get the length of the string. But I only want the amount of digits. Can someone please help me?</p>
