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 = function(str){
      if(str[0]=='-'){ 
      	str = str.substring(1) 
      }
      return [...str].every(x=>nums.has(x));
    }


    alert(hasOnlyNumbers('-3243234332'));
    alert(hasOnlyNumbers('notnumbers'));