If my understanding is correct, you are in need of a regex pattern that can successfully match the specified numbers.
Below is an example demonstrating such a pattern:
/^[-+]?((\.\d+)|(\d+(\.\d+)?))$/
In this pattern, [-+]?
matches the initial +/-
sign, (\.\d+)
matches numbers with a starting decimal point, and (\d+(\.\d+)?)
matches complete numbers.
This pattern should effectively match numbers like: '-1', '+1', '50', '.27', '2.27'
Sample code snippet:
const testNumbers = ['-1', '+1', '50', '.27', '2.27'];
const pattern = /^[-+]?((\.\d+)|(\d+(\.\d+)?))$/;
const isAllMatched = testNumbers.every(testNumber => testNumber === testNumber.match(pattern)?.[0]);
console.log('isAllMatched: ', isAllMatched);