You can do it with this regex
let str = '24?22?3'
digitsOnly = str.replace(/\D/g, '');
//digitsOnly='24223'