JSFiddle - React, Tailwind, and code Playground

HTML

<body>
    <input id="input" type="text" />
</body>

JavaScript

$("#input").keypress(function(e){
    var value = $(this).val().replace(" ", "");
    var words = value.split(",");
    
    if(words.length > 5){
        //alert("Hey! That's more than 5 words!");
        e.preventDefault();
    }
});