JSFiddle - React, Tailwind, and code Playground
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<input type="text" class="input-phone">
JavaScript
$('.input-phone').each(function() {
$(this).on('input propertychange', function (e) {
var $target = $(e.target), position = $target[0].selectionEnd, length = $target.val().length;
$target.val($target.val().replace(/[^\dA-Z]/g, '').replace(/(.{2})/g, '$1 ').trim());
$target[0].selectionEnd = position += (($target.val().charAt(position - 1) === ' ' && $target.val().charAt(length - 1) === ' ' && length !== $target.val().length) ? 1 : 0);
});
});