Intenta suscribirte al evento [`input`](https://developer.mozilla.org/en-US/docs/Web/Events/input) en lugar de `keyup`. Aprovecho para sugerir una forma "_mas simple_" de lograr el mismo resultado. ###Solución: <!-- begin snippet: js hide: false console: true babel: false --> <!-- language: lang-js --> var separador = document.getElementById('separadorMiles'); separador.addEventListener('input', (e) => { var entrada = e.target.value.split(','), parteEntera = entrada[0].replace(/\./g, ''), parteDecimal = entrada[1], salida = parteEntera.replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1."); e.target.value = salida + (parteDecimal !== undefined ? ',' + parteDecimal : ''); }, false); <!-- language: lang-html --> <input type="text" name="inversion" placeholder="$10.000.000" class="form-control" id="separadorMiles" required><br> <!-- end snippet --> Referencia: * [Number Formatting Using `string.replace` in JavaScript](https://blog.tompawlak.org/number-currency-formatting-javascript)