Reputation: 303
I want a regex which only accepts positive and negative numbers. It should not include decimal point or any other characters except positive and negative numbers.
I have tried below regex but it accepts decimal point.
^-?\d*\.{0,1}\d+$
The regex should not allow any decimal point even it is before 0 e.g. 122334.0000
Thank you.
Upvotes: 0
Views: 298
Reputation: 7949
You can do something like the below code.
^\-?[1-9]\d{0,2}$
OR
^[+-]?\d+$
Upvotes: 1