Restrict table data value to 4 digits

I am trying to build a simple calculator using HTML, CSS and Vanilla Javascript. Where I want to make sure that the input field (display screen) does not have more than 4 digits in the first operand and similarly for the next operands to follow.

Story so far
index.html

<table class="calculator">
    <tr>
        <td colspan="4"><input class="display-box" type="text" id="result" disabled /></td>
    </tr>
    <tr>
        <td><input class="button" type="button" value="1" onclick="display('1')" /> </td>
        <td><input class="button" type="button" value="2" onclick="display('2')" /> </td>
        <td><input class="button" type="button" value="3" onclick="display('3')" /> </td>
        <td><input class="button" type="button" value="*" onclick="display('*')" /></td>
    </tr>
    ...
</table>

script.js

function display(value) {
    document.getElementById("result").value += value;
    var ops = ["+", "-", "%", "*", "/"];
    result=document.getElementById("result").value
    console.log(result)
    if(ops.includes(value)){
        result=0
        console.log("Ops found!")
    }
    result=document.getElementById("result").value
    result=result.replace(/[^0-9]/g, '');
    console.log(result)
    if(result>9999){
        document.getElementById("result").value = "Error"
        alert("Error: Entered more than 4 digits")
    }
}