How to prevent input from entering incorrect content

question: add input rules to the
input box, such as

        e.detail.value = e.detail.value.replace(/\.{2,}/g, ".")
        e.detail.value = e.detail.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, "$1$2.$3")

but the effect of using replace is not good, because it is judged after the user input, whether it can be realized that when the user inputs, if the input is wrong, the user will not be allowed to enter, and there will not be the feeling of flickering before

Mar.31,2021

test.onkeypress = function (e) {
    const newString = this.value + String.fromCharCode(e.keyCode);
    function testSomething(newString, keyCode) {
        // 
        return keyCode > 100;
    }
    if (testSomething(newString, e.keyCode)) {
        return true;
    }
    return false;
}

isn't it possible to judge in real time by listening to input events?


there is something wrong with your thinking. How do you know what user input will be? if you don't wait for user input, what will you judge?
so there must be user input, and the result does not meet the requirements for processing (for example, more than 2 points are deleted here).
is followed by reserved 2 decimal places.

Menu