I've seen this question asked a few times (here for example), and despite my best attempts to replicate, and reading up on regex, this doesn't seem to work:
$("#button").click(function () {
new_number = $("#the_input").val();
new_number = new_number.replace(/[^0-9]+/g, '')
// also doesn't work: (/\D/g, '')
$("#result").html(new_number);
});
The Goal: On button click, collect value from input, remove NON-NUMBERS and output string inside a div.
The Result: When I put a number in, it comes out fine. When I put a NON-NUMBER & a NUMBER, or anything but a number it comes out blank. It seems to replace the whole string, and not just the matched characters.
Help?
numberwhen you enter a non numerical value it does not return a value, change the type to text and check - jsfiddle.net/arunpjohny/3QZdp/1