I have the following function, it is to enter only numbers with signs

I have the following function:

function formatNumber(num) {
return “$” + num
.toFixed(2)
.replace(/(\d)(?=(\d{3})+(?!\d))/g, “$1,”);
}

export function input2_change(event) {
$w(‘#input2’).value = formatNumber(Number($w(‘#input2’).value));}

The code is only for entering numbers and signs, and that the numbers are automatically aligned for example $1, but I would like that when letters are entered, the field is automatically deleted.
With this code, when you enter letters in the text field instead of deleting it, NaN appears and the field is not deleted.

You can replace the alphabet with ‘’ to delete it. See code below:
.replace(/[^a-zA-Z 0-9]+/g,‘’);