JSFiddle - React, Tailwind, and code Playground

Tags Input Testing

by Jennifer Perrin

HTML

<input class="" name="tags" id="tags" required="required" value="" type="text" style="width: 90%" />

JavaScript

var maxTags = 6;

$("#tags").keypress(function(e) {
    var tagsLength = $('#tags').val().split(',').length;
    
    if (tagsLength == maxTags) {
        if (e.which !== 8) {
        	e.preventDefault();
        }
    }
});