JSFiddle - React, Tailwind, and code Playground

HTML

<input type="test" class="name" />

JavaScript

$('.name').keyup(function() {
    var $th = $(this);
    $th.val($th.val().replace(/(\s{2,})|[^a-zA-Z']/g, ' '));
    $th.val($th.val().replace(/^\s*/, ''));
    });