document.querySelector('#test').addEventListener('input', function() { this.value = this.value.replace(/[,\.]+/, '.').replace(/[^\d.]|(?<=\.\d*)\./, ''); });