Reputation: 77
I've been working on a project with lots of previous developer validation issues and am trying to clean up some issues and add validation in spots.
I generally use this simple regex that allows only positive whole values and can accept commas if they are entered:
"^([0-9]*,?)*$"
But in this case my program won't run if 0
is the value entered, so I need 1
to be the minimum value allowed. All else is the same. No decimals or any of that stuff.
I'm assuming I just need to add "not 0" to my regex, but not sure how to do that.
Allowed:
3,200
650
5
134560
100,000
Not Allowed:
0
3.2
-3.2
Thanks for your help!
Upvotes: 1
Views: 2478
Reputation: 71568
Simply use this:
^[1-9]([0-9]*,?)*$
The first character cannot be a 0
and since it isn't optional either...
Upvotes: 1