JSFiddle - React, Tailwind, and code Playground

HTML

<input onkeypress="return validate(event);" />

JavaScript

// Check if key press is a number
function validate(e) 
{ 
    var charCode = e.which || e.keyCode;

    if (charCode > 31 && (charCode < 48 || charCode > 57)) 
    {
        alert("Enter Numbers Only");
        return false;
    }
    return true;
}