JSFiddle - React, Tailwind, and code Playground

HTML

<input type="text">

JavaScript

$('input').keyup( function() {
    var userinput = $(this).val();
    var pattern = /^[A-Z]'?[-a-zA-Z]+$/i
    
    if(!pattern.test(userinput))
    {
        $(this).css("background","red");
    } else {
        $(this).css("background","green");
    }
});