check repeated data in input while typing

I have an input

<input required type="text" id="Editbox1"name="EditboxD" value="00" maxlength="2">

I need to check if the user wrote a repeated value like 00 or 22 while he is typing and showing alert !

Answers 1

  • Here is the shorthand most efficient way

    var last;
    document.getElementById('Editbox1').addEventListener('keypress',(e)=>last = (last === undefined) ? e.keyCode : (e.keyCode === last) ? alert('repeated data') : e.keyCode);
    

Related Articles