JSFiddle - React, Tailwind, and code Playground

HTML

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

JavaScript

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