JSFiddle - React, Tailwind, and code Playground

by AndyE

HTML

<input type="text">

JavaScript

$("input").keyup(function () {
    $(this).val($(this).val().replace(/[^A-Z0-9-]|-(?:-)|^-|-$/gi, ''));
})