I think this regular expression will serve your purpose:
var num = txt.replace(/[^0-9]/g,'');
Where txt
is your string.
It basically rips off anything that is not a digit.
I think you can achieve the same thing by using this as well :
var num = txt.replace(/\D/g,'');