JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" id="test"/>
<div></div>
JavaScript
$(document).ready(function(){
var div = $("div");
(function(){//anon function for scope
var prevVal = $("#test").val();
$('#test').on("input", function (e) {//'input will also handle paste event. i t will hadle every input'
if(/*your `if` here*/ Math.random() > 0.3){
div.text(true);
this.value = prevVal;//You shall not pass!
} else { div.text(false) }
prevVal = this.value;
});
})();
});