JSFiddle - React, Tailwind, and code Playground

by gaby de wilde

JavaScript

nums = new Set(['1','2','3','4','5','6','7','8','9','0']);

hasOnlyNumbers = str => [... 
	str[0] == '-' ? 
  str.substring(1) :
  str 
  ].every(x=>nums.has(x));
   
alert(      hasOnlyNumbers('-3243234332')     );
alert(      hasOnlyNumbers('notnumbers')     );