JSFiddle - React, Tailwind, and code Playground

by Joe Saad

HTML

<input type="text">
<div id="char"></div>

JavaScript

$('input').keypress(function (e) {
    $('#char').text(e.which);
    var regex = new RegExp("^[a-zA-Z0-9-*:. \"]+$");
    var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
    var allowedKeys = [8, 32, 37, 38, 39, 49, 40];
    if ((regex.test(str) || ( (allowedKeys.indexOf(e.keyCode) > -1 && !e.shiftKey) || (e.which === "" || (e.which ==0 && e.keyCode != 0) ) ) ) && (e.which !=39)  ){
        console.log(e.which + ' - ' + e.keyCode + ' - '+ e.charCode);
        return true;
    } else {
        //e.preventDefault();
        console.log(e.which + ' * ' + e.keyCode + ' * ' + e.charCode);
        return false;
    }
});