How to make sure that there are spaces and a symbol at the end and that when the value of the slider changes, there are also spaces with the symbol, and now it turns out only when you enter the value from the keyboard, everything is added. Help :(
var inp_1 = $('#test'); var slider2 = $('#runner_2').slider({ range: 'max', min: 100000, max: 1000000, value: 180000, step: 20000, slide: function(event, ui) { // присваеваем значение бегунка инпуту inp_1.val(ui.value); var test = inp_1.val; if (ui.value > 100000) { // если были изменения, то показываем шаг 2 $('.s-calc-step2').css('display', 'block'); } else {} } }); test.onkeypress = event => { // Control buttons if (event.key.length > 1) return true; test.value = (test.value + event.key) .replace(/\D/g, '') .replace(/(\d)(?=(\d{3})+([^\d]|$))/g, '$1 ') + '₽'; event.preventDefault(); } <input id="test" type="text"> <div id="runner_2"></div> <link href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.js"></script>