JSFiddle - React, Tailwind, and code Playground
JavaScript
nums = new Set(['.','1','2','3','4','5','6','7','8','9','0']);
hasOnlyNumbers = function(str){
if(str.split('.').length > 2) {
return false
}
if(str[0]=='-'){
str = str.substring(1)
}
return [...str].every(x=>nums.has(x));
}
alert(hasOnlyNumbers('-3243.234332'));
alert(hasOnlyNumbers('-3243.234.3.32'));