The task is pretty simple, but I've not been able to come up with a good solution yet: a string can contain numbers, dashes and pluses, or only numbers.
^[0-9+-]+$
does most of what I need, except when a user enters garbage like "+-+–+"
I've not had luck with regular lookahead, since the dashes and pluses could potentially be anywhere in the string.
Valid strings:
- 234654
- 24-3+-2
- -234
- 25485+
Invalid:
- ++–+
Best Solution
How about this:
which means "one or more digits, each of which can be preceded or followed by an optional plus or minus".
Here's a Python test script:
which prints this: