I have an input value that excepts decimal numbers but the problem is that the decimal point or the period point repeat more than one time inside the input value for example 1.2.3 instead of this 1.23 thank you.
let input = document.querySelectorAll("input")
let arr = []
function period_noRepeat(x){
const result = []
const input = Array.isArray(x)? x: x.split('')
for(let i = 0; i < input.length; ++i){
if(input[i] == input[i + 1] && input[i] != 1 * input[i]) continue
result.push(input[i])
}
return result;
}
const regex = /[^0-9\.]/
input.forEach(function(item){
item.addEventListener("input",function(e){
item.value = item.value.replace(regex,"")
arr = item.value.split("")
item.value = period_noRepeat(arr).join("")
})
})
<input type="text" class="dividend" >
<input type="text" class="divisor" dir = "rtl">