How js restricts input to enter only 4 decimal places and enter only 4 decimal places

as a question, I now have 4 input,4 input, all of which can only enter digits and decimal places from the beginning of the input, and can only enter 4 decimal places after the decimal point. If the input format is incorrect, for example, if I write an s into it, the s cannot be written into it. If you want to use the key event, how to solve it and find a solution

Mar.10,2021

regular verification is fine

/^(-?\d+)(\.\d{4})?$/

<input id="input">

var input = document.getElementById('input');

var reg = /^\d+(\.)?\d{0,4}?$/;

var oldValue = ''

input.addEventListener('input',function(e){
  if(reg.test(e.target.value)){ 
    oldValue = e.target.value
  }else if(e.target.value){
    e.target.value = oldValue;
  } else{
    e.target.value = '';
    oldValue = '';
  }
});

input.addEventListener('change',function(e){
  if(e.target.value.endsWith('.')){
    e.target.value = e.target.value.slice(0,-1);
   } 
});

<input  type="text" onkeyup="clearNoNum(this)">
function clearNoNum(obj){

        obj.value = obj.value.replace(/[^\d.]/g,""); //"""."

        obj.value = obj.value.replace(/^\./g,""); //

        obj.value = obj.value.replace(/\.{2,}/g,"."); //. 

        obj.value = obj.value.replace(".","$-sharp$").replace(/\./g,"").replace("$-sharp$",".");

        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d\d\d\d\d).*$/,'$1$2.$3'); //
    

        $('input[name="buyMoney"]').val(accMul($('input[name="buyPrice"]').val(),$('input[name="buyVal"]').val()));

        $('input[name="saleMoney"]').val(accMul($('input[name="salePrice"]').val(),$('input[name="saleVal"]').val()));
    }

    // 
    function accMul(arg1,arg2){
        {   
            if(arg1 == undefined || arg2 == undefined){
                return
            }
            var m=0,s1=arg1.toString(),s2=arg2.toString();   
            try{m+=s1.split(".")[1].length}catch(e){}   
            try{m+=s2.split(".")[1].length}catch(e){}   
            return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m)   
        }
    }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b37c97-4ed27.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b37c97-4ed27.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?