JSFiddle - React, Tailwind, and code Playground

HTML

<input  type="text" size="5" id="number" class='accessories_qty' value="" />
<button id="test"> test </button><br/><br/>

 <input type="text" id ="fax_field" name="fax_field"/>

JavaScript

$('#test').click(function(){ 
if ($('.accessories_qty').val().trim().length > 0) {
			value = $('.accessories_qty').val().trim();
			(Math.floor(value) == value) ? alert('Entered value is number') : alert("Value should be a numeric")
		} else {
			alert("Value should be a numeric");
		}
});



$("#fax_field").keyup(function(event) {
		var limitField = $(this).val().trim().length;
		this.value = this.value.replace(/[^0-9_\-\.]/g, '');	
});