Miguel, you need to take some time to understand the code. Your first code chunk is what we developed in response to an earlier question you posted. It does the job, except that you want to allow the user to be able to input non-numeric characters (commas, specifically). You therefore want to ‘clean up’ the input before processing it.
To do that, you can use the ‘replace()’ method on the input string, with the appropriate regex. Buried in your second chunk of code is a replace example, applied to an input value. That’s what you need to use up in the original chunk of code.
That’s JavaScript. If you do some searches on removing non-numeric characters from a text string in JavaScript you’ll find simple explanations and simple examples (without all the extraneous code you’ve got in that second chunk).