JSFiddle - React, Tailwind, and code Playground
by Suyog
HTML
<input type="text" name="hei" id="hei" class="textarea" placeholder="e.g. 163" />
JavaScript
$(function(){
$('#hei').keypress(function(event)
{
var charCode = (event.which) ? event.which : event.keyCode
if (
(charCode != 45 || $(this).val().indexOf('-') != -1) && // “-” CHECK MINUS, AND ONLY ONE.
(charCode != 46 || $(this).val().indexOf('.') != -1) && // “.” CHECK DOT, AND ONLY ONE.
(charCode < 48 || charCode > 57))
return false;
return true;
});
});